diff --git a/src/main/java/org/eclipsefoundation/git/eca/api/GithubAPI.java b/src/main/java/org/eclipsefoundation/git/eca/api/GithubAPI.java index ec77f9021627078cfe9ba499f54a099afdb66204..17f7229b0e8a52112b4d748f74aa918f6b0f2c66 100644 --- a/src/main/java/org/eclipsefoundation/git/eca/api/GithubAPI.java +++ b/src/main/java/org/eclipsefoundation/git/eca/api/GithubAPI.java @@ -52,9 +52,9 @@ public interface GithubAPI { * @return information about the given pull request if it exists. */ @GET - @Path("repos/{repoFull}/pulls/{pullNumber}") + @Path("repos/{org}/{repo}/pulls/{pullNumber}") public PullRequest getPullRequest(@HeaderParam(HttpHeaders.AUTHORIZATION) String bearer, - @HeaderParam("X-GitHub-Api-Version") String apiVersion, @PathParam("repoFull") String repoFull, + @HeaderParam("X-GitHub-Api-Version") String apiVersion, @PathParam("org") String organization, @PathParam("repo") String repo, @PathParam("pullNumber") int pullNumber); /** @@ -62,14 +62,14 @@ public interface GithubAPI { * * @param bearer authorization header value, access token for application with access to repo * @param apiVersion the version of the GH API to target when making the request - * @param repoFull the full repo name that is being targeted + * @param repo the repo name that is being targeted * @param pullNumber the pull request number * @return list of commits associated with the pull request, wrapped in a jax-rs response */ @GET - @Path("repos/{repoFull}/pulls/{pullNumber}/commits") + @Path("repos/{org}/{repo}/pulls/{pullNumber}/commits") public RestResponse<List<GithubCommit>> getCommits(@HeaderParam(HttpHeaders.AUTHORIZATION) String bearer, - @HeaderParam("X-GitHub-Api-Version") String apiVersion, @PathParam("repoFull") String repoFull, + @HeaderParam("X-GitHub-Api-Version") String apiVersion, @PathParam("org") String organization, @PathParam("repo") String repo, @PathParam("pullNumber") int pullNumber); /** @@ -77,15 +77,16 @@ public interface GithubAPI { * * @param bearer authorization header value, access token for application with access to repo * @param apiVersion the version of the GH API to target when making the request - * @param repoFull the full repo name that is being targeted + * @param organization the organization that owns the targeted repo + * @param repo the repo name that is being targeted * @param prHeadSha the head SHA for the request * @param commitStatusUpdate the status body sent with the request * @return JAX-RS response to check for success or failure based on status code. */ @POST - @Path("repos/{repoFull}/statuses/{prHeadSha}") + @Path("repos/{org}/{repo}/statuses/{prHeadSha}") public Response updateStatus(@HeaderParam(HttpHeaders.AUTHORIZATION) String bearer, - @HeaderParam("X-GitHub-Api-Version") String apiVersion, @PathParam("repoFull") String repoFull, + @HeaderParam("X-GitHub-Api-Version") String apiVersion, @PathParam("org") String organization, @PathParam("repo") String repo, @PathParam("prHeadSha") String prHeadSha, GithubCommitStatusRequest commitStatusUpdate); /** diff --git a/src/main/java/org/eclipsefoundation/git/eca/api/models/GithubWebhookRequest.java b/src/main/java/org/eclipsefoundation/git/eca/api/models/GithubWebhookRequest.java index 697f71430f9904135eb2d0dda4fb7b32462ed5f4..e68392db3e0f3b901b081a83cfe5dfce45f9265f 100644 --- a/src/main/java/org/eclipsefoundation/git/eca/api/models/GithubWebhookRequest.java +++ b/src/main/java/org/eclipsefoundation/git/eca/api/models/GithubWebhookRequest.java @@ -14,6 +14,7 @@ package org.eclipsefoundation.git.eca.api.models; import jakarta.annotation.Nullable; import org.eclipsefoundation.git.eca.dto.GithubWebhookTracking; +import org.eclipsefoundation.utils.helper.TransformationHelper; import com.fasterxml.jackson.databind.annotation.JsonDeserialize; import com.fasterxml.jackson.databind.annotation.JsonPOJOBuilder; @@ -55,6 +56,13 @@ public abstract class GithubWebhookRequest { * @return the reconstructed request. */ public static GithubWebhookRequest buildFromTracking(GithubWebhookTracking tracking) { + String[] repoNameParts = tracking.getRepositoryFullName().split("\\/"); + if (repoNameParts.length != 2) { + throw new IllegalStateException("A repo full name should always have 2 parts, organization name and repo name: " + + TransformationHelper.formatLog(tracking.getRepositoryFullName())); + } + String org = repoNameParts[0]; + String repo = repoNameParts[1]; return builder() .setInstallation(Installation.builder().setId(tracking.getInstallationId()).build()) .setPullRequest(PullRequest @@ -66,6 +74,8 @@ public abstract class GithubWebhookRequest { .setRepository(Repository .builder() .setFullName(tracking.getRepositoryFullName()) + .setName(repo) + .setOwner(RepositoryOwner.builder().setLogin(org).build()) .setHtmlUrl("https://github.com/" + tracking.getRepositoryFullName()) .build()) .build(); @@ -92,6 +102,10 @@ public abstract class GithubWebhookRequest { public abstract String getFullName(); + public abstract String getName(); + + public abstract RepositoryOwner getOwner(); + public abstract String getHtmlUrl(); public static Builder builder() { @@ -103,12 +117,35 @@ public abstract class GithubWebhookRequest { public abstract static class Builder { public abstract Builder setFullName(String fullName); + public abstract Builder setName(String name); + + public abstract Builder setOwner(RepositoryOwner owner); + public abstract Builder setHtmlUrl(String htmlUrl); public abstract Repository build(); } } + @AutoValue + @JsonDeserialize(builder = AutoValue_GithubWebhookRequest_RepositoryOwner.Builder.class) + public abstract static class RepositoryOwner { + + public abstract String getLogin(); + + public static Builder builder() { + return new AutoValue_GithubWebhookRequest_RepositoryOwner.Builder(); + } + + @AutoValue.Builder + @JsonPOJOBuilder(withPrefix = "set") + public abstract static class Builder { + public abstract Builder setLogin(String fullName); + + public abstract RepositoryOwner build(); + } + } + @AutoValue @JsonDeserialize(builder = AutoValue_GithubWebhookRequest_PullRequest.Builder.class) public abstract static class PullRequest { diff --git a/src/main/java/org/eclipsefoundation/git/eca/helper/GithubValidationHelper.java b/src/main/java/org/eclipsefoundation/git/eca/helper/GithubValidationHelper.java index 5d8992d6311c63ea9eb32b5f8efee4601a14f4b6..054ebad6739c2b353c7ba933051b4fde7b5fd717 100644 --- a/src/main/java/org/eclipsefoundation/git/eca/helper/GithubValidationHelper.java +++ b/src/main/java/org/eclipsefoundation/git/eca/helper/GithubValidationHelper.java @@ -108,10 +108,10 @@ public class GithubValidationHelper { public ValidationResponse validateIncomingRequest(RequestWrapper wrapper, String org, String repoName, Integer prNo, boolean forceRevalidation) { // use logging helper to sanitize newlines as they aren't needed here - String fullRepoName = TransformationHelper.formatLog(org + '/' + repoName); + String fullRepoName = getFullRepoName(org, repoName); // get the installation ID for the given repo if it exists, and if the PR noted exists String installationId = ghAppService.getInstallationForRepo(org, repoName); - Optional<PullRequest> prResponse = ghAppService.getPullRequest(installationId, fullRepoName, prNo); + Optional<PullRequest> prResponse = ghAppService.getPullRequest(installationId, org, repoName, prNo); if (StringUtils.isBlank(installationId)) { throw new BadRequestException("Could not find an ECA app installation for repo name: " + fullRepoName); } else if (prResponse.isEmpty()) { @@ -120,7 +120,7 @@ public class GithubValidationHelper { // prepare the request for consumption String repoUrl = getRepoUrl(org, repoName); - ValidationRequest vr = generateRequest(installationId, fullRepoName, prNo, repoUrl); + ValidationRequest vr = generateRequest(installationId, org, repoName, prNo, repoUrl); // build the commit sha list based on the prepared request List<String> commitShas = vr.getCommits().stream().map(Commit::getHash).toList(); @@ -131,7 +131,7 @@ public class GithubValidationHelper { LOGGER.debug("Found {} commits for '{}#{}'", commitShas.size(), fullRepoName, prNo); // retrieve the webhook tracking info, or generate an entry to track this PR if it's missing. - GithubWebhookTracking updatedTracking = retrieveAndUpdateTrackingInformation(wrapper, installationId, fullRepoName, + GithubWebhookTracking updatedTracking = retrieveAndUpdateTrackingInformation(wrapper, installationId, org, repoName, prResponse.get()); if (updatedTracking == null) { throw new ServerErrorException("Error while attempting to revalidate request, try again later.", @@ -167,17 +167,22 @@ public class GithubValidationHelper { * @return the populated validation request for the Github request information */ @SuppressWarnings("null") - public ValidationRequest generateRequest(String installationId, String repositoryFullName, int pullRequestNumber, + public ValidationRequest generateRequest(String installationId, String orgName, String repositoryName, int pullRequestNumber, String repositoryUrl) { - checkRequestParameters(installationId, repositoryFullName, pullRequestNumber); + checkRequestParameters(installationId, orgName, repositoryName, pullRequestNumber); // get the commits that will be validated, don't cache as changes can come in too fast for it to be useful + if (LOGGER.isTraceEnabled()) { + LOGGER + .trace("Retrieving commits for PR {} in repo {}/{}", pullRequestNumber, TransformationHelper.formatLog(orgName), + TransformationHelper.formatLog(repositoryName)); + } List<GithubCommit> commits = middleware .getAll(i -> ghApi - .getCommits(jwtHelper.getGhBearerString(installationId), apiVersion, repositoryFullName, pullRequestNumber)); + .getCommits(jwtHelper.getGhBearerString(installationId), apiVersion, orgName, repositoryName, pullRequestNumber)); if (LOGGER.isTraceEnabled()) { LOGGER - .trace("Retrieved {} commits for PR {} in repo {}", commits.size(), pullRequestNumber, - TransformationHelper.formatLog(repositoryUrl)); + .trace("Found {} commits for PR {} in repo {}/{}", commits.size(), pullRequestNumber, + TransformationHelper.formatLog(orgName), TransformationHelper.formatLog(repositoryName)); } // set up the validation request from current data @@ -223,7 +228,8 @@ public class GithubValidationHelper { // send the success status for the head SHA ghApi .updateStatus(jwtHelper.getGhBearerString(request.getInstallation().getId()), apiVersion, - request.getRepository().getFullName(), request.getMergeGroup().getHeadSha(), + request.getRepository().getOwner().getLogin(), request.getRepository().getName(), + request.getMergeGroup().getHeadSha(), GithubCommitStatusRequest .builder() .setDescription("Commits in merge group should be previously validated, auto-passing HEAD commit") @@ -274,11 +280,11 @@ public class GithubValidationHelper { * @param pr the pull request targeted by the validation request. * @return a new or updated tracking object, or null if there was an error in saving the information */ - public GithubWebhookTracking retrieveAndUpdateTrackingInformation(RequestWrapper wrapper, String installationId, - String repositoryFullName, PullRequest pr) { + public GithubWebhookTracking retrieveAndUpdateTrackingInformation(RequestWrapper wrapper, String installationId, String orgName, + String repositoryName, PullRequest pr) { return updateGithubTrackingIfMissing(wrapper, - getExistingRequestInformation(wrapper, installationId, repositoryFullName, pr.getNumber()), pr, installationId, - repositoryFullName); + getExistingRequestInformation(wrapper, installationId, orgName, repositoryName, pr.getNumber()), pr, installationId, + orgName, repositoryName); } /** @@ -290,8 +296,8 @@ public class GithubValidationHelper { * @param fullRepoName the full repo name for the validation request */ public GithubWebhookTracking updateGithubTrackingIfMissing(RequestWrapper wrapper, Optional<GithubWebhookTracking> tracking, - PullRequest request, String installationId, String fullRepoName) { - String sanitizedRepoName = TransformationHelper.formatLog(fullRepoName); + PullRequest request, String installationId, String orgName, String repositoryName) { + String fullRepoName = getFullRepoName(orgName, repositoryName); // if there is no tracking present, create the missing tracking and persist it GithubWebhookTracking updatedTracking; if (tracking.isEmpty()) { @@ -299,13 +305,13 @@ public class GithubValidationHelper { updatedTracking.setInstallationId(installationId); updatedTracking.setLastUpdated(DateTimeHelper.now()); updatedTracking.setPullRequestNumber(request.getNumber()); - updatedTracking.setRepositoryFullName(sanitizedRepoName); + updatedTracking.setRepositoryFullName(fullRepoName); updatedTracking.setNeedsRevalidation(false); updatedTracking.setManualRevalidationCount(0); if (!"open".equalsIgnoreCase(request.getState())) { LOGGER .warn("The PR {} in {} is not in an open state, and will not be validated to follow our validation practice", - updatedTracking.getPullRequestNumber(), sanitizedRepoName); + updatedTracking.getPullRequestNumber(), fullRepoName); } } else { // uses the DB version as a base if available @@ -319,11 +325,11 @@ public class GithubValidationHelper { List<GithubWebhookTracking> savedTracking = dao .add(new RDBMSQuery<>(wrapper, filters.get(GithubWebhookTracking.class)), Arrays.asList(updatedTracking)); if (savedTracking.isEmpty()) { - LOGGER.warn("Unable to create new GH tracking record for request to validate {}#{}", sanitizedRepoName, request.getNumber()); + LOGGER.warn("Unable to create new GH tracking record for request to validate {}#{}", fullRepoName, request.getNumber()); return null; } // return the updated tracking when successful - LOGGER.debug("Created/updated GH tracking record for request to validate {}#{}", sanitizedRepoName, request.getNumber()); + LOGGER.debug("Created/updated GH tracking record for request to validate {}#{}", fullRepoName, request.getNumber()); return savedTracking.get(0); } @@ -335,9 +341,10 @@ public class GithubValidationHelper { * @param pullRequestNumber the pull request number that is being processed currently * @return the webhook tracking record if it can be found, or an empty optional. */ - public Optional<GithubWebhookTracking> getExistingRequestInformation(RequestWrapper wrapper, String installationId, - String repositoryFullName, int pullRequestNumber) { - checkRequestParameters(installationId, repositoryFullName, pullRequestNumber); + public Optional<GithubWebhookTracking> getExistingRequestInformation(RequestWrapper wrapper, String installationId, String orgName, + String repositoryName, int pullRequestNumber) { + checkRequestParameters(installationId, orgName, repositoryName, pullRequestNumber); + String repositoryFullName = getFullRepoName(orgName, repositoryName); MultivaluedMap<String, String> params = new MultivaluedHashMap<>(); params.add(GitEcaParameterNames.INSTALLATION_ID_RAW, installationId); params.add(GitEcaParameterNames.REPOSITORY_FULL_NAME_RAW, repositoryFullName); @@ -374,7 +381,7 @@ public class GithubValidationHelper { jwtHelper.getGithubAccessToken(request.getInstallation().getId()).getToken()); ghApi .updateStatus(jwtHelper.getGhBearerString(request.getInstallation().getId()), apiVersion, - request.getRepository().getFullName(), pr.getHead().getSha(), + request.getRepository().getOwner().getLogin(), request.getRepository().getName(), pr.getHead().getSha(), GithubCommitStatusRequest .builder() .setDescription(state.getMessage()) @@ -408,13 +415,16 @@ public class GithubValidationHelper { * @param pullRequestNumber the pull request number that is being processed currently * @throws BadRequestException if at least one of the parameters is in an invalid state. */ - private void checkRequestParameters(String installationId, String repositoryFullName, int pullRequestNumber) { + private void checkRequestParameters(String installationId, String org, String repoName, int pullRequestNumber) { List<String> missingFields = new ArrayList<>(); if (StringUtils.isBlank(installationId)) { missingFields.add(GitEcaParameterNames.INSTALLATION_ID_RAW); } - if (StringUtils.isBlank(repositoryFullName)) { - missingFields.add(GitEcaParameterNames.REPOSITORY_FULL_NAME_RAW); + if (StringUtils.isBlank(org)) { + missingFields.add(GitEcaParameterNames.ORG_NAME_RAW); + } + if (StringUtils.isBlank(repoName)) { + missingFields.add(GitEcaParameterNames.REPOSITORY_NAME_RAW); } if (pullRequestNumber < 1) { missingFields.add(GitEcaParameterNames.PULL_REQUEST_NUMBER_RAW); @@ -425,5 +435,16 @@ public class GithubValidationHelper { throw new BadRequestException("Missing fields in order to prepare request: " + StringUtils.join(missingFields, ' ')); } } + + /** + * Retrieves the full repo name for a given org and repo name, used for storage and legacy support. + * + * @param org organization name being targeted + * @param repo name of repo being targeted + * @return the full repo name, following format of org/repo + */ + public static String getFullRepoName(String org, String repo) { + return TransformationHelper.formatLog(org + '/' + repo); + } } diff --git a/src/main/java/org/eclipsefoundation/git/eca/namespace/GitEcaParameterNames.java b/src/main/java/org/eclipsefoundation/git/eca/namespace/GitEcaParameterNames.java index e1d0c35d55e25cca971ed8bb6debf19ad6a08843..454a9b04ba6d0ed109c8de849d091a550aeda8c1 100644 --- a/src/main/java/org/eclipsefoundation/git/eca/namespace/GitEcaParameterNames.java +++ b/src/main/java/org/eclipsefoundation/git/eca/namespace/GitEcaParameterNames.java @@ -36,6 +36,8 @@ public final class GitEcaParameterNames implements UrlParameterNamespace { public static final String SINCE_RAW = "since"; public static final String UNTIL_RAW = "until"; public static final String REPOSITORY_FULL_NAME_RAW = "repo_full_name"; + public static final String ORG_NAME_RAW = "org"; + public static final String REPOSITORY_NAME_RAW = "repo_name"; public static final String INSTALLATION_ID_RAW = "installation_id"; public static final String APPLICATION_ID_RAW = "application_id"; public static final String LAST_UPDATED_BEFORE_RAW = "last_updated_before"; @@ -58,6 +60,8 @@ public final class GitEcaParameterNames implements UrlParameterNamespace { public static final UrlParameter SINCE = new UrlParameter(SINCE_RAW); public static final UrlParameter UNTIL = new UrlParameter(UNTIL_RAW); public static final UrlParameter REPOSITORY_FULL_NAME = new UrlParameter(REPOSITORY_FULL_NAME_RAW); + public static final UrlParameter REPOSITORY_NAME = new UrlParameter(REPOSITORY_NAME_RAW); + public static final UrlParameter ORG_NAME = new UrlParameter(ORG_NAME_RAW); public static final UrlParameter INSTALLATION_ID = new UrlParameter(INSTALLATION_ID_RAW); public static final UrlParameter APPLICATION_ID = new UrlParameter(APPLICATION_ID_RAW); public static final UrlParameter LAST_UPDATED_BEFORE = new UrlParameter(LAST_UPDATED_BEFORE_RAW); @@ -69,8 +73,8 @@ public final class GitEcaParameterNames implements UrlParameterNamespace { public List<UrlParameter> getParameters() { return Arrays .asList(COMMIT_ID, SHA, SHAS, PROJECT_ID, PROJECT_IDS, NOT_IN_PROJECT_IDS, REPO_URL, FINGERPRINT, USER_ID, PROJECT_PATH, - PARENT_PROJECT, STATUS_ACTIVE, STATUS_DELETED, SINCE, UNTIL, REPOSITORY_FULL_NAME, INSTALLATION_ID, APPLICATION_ID, - LAST_UPDATED_BEFORE, PULL_REQUEST_NUMBER, USER_MAIL, NEEDS_REVALIDATION); + PARENT_PROJECT, STATUS_ACTIVE, STATUS_DELETED, SINCE, UNTIL, REPOSITORY_FULL_NAME, ORG_NAME, REPOSITORY_NAME, + INSTALLATION_ID, APPLICATION_ID, LAST_UPDATED_BEFORE, PULL_REQUEST_NUMBER, USER_MAIL, NEEDS_REVALIDATION); } } diff --git a/src/main/java/org/eclipsefoundation/git/eca/resource/GithubWebhooksResource.java b/src/main/java/org/eclipsefoundation/git/eca/resource/GithubWebhooksResource.java index 33c519f60ec77010874210d96d25938fa9493eef..453188aa05016b455ac25acbcd623f9b8a4d4a73 100644 --- a/src/main/java/org/eclipsefoundation/git/eca/resource/GithubWebhooksResource.java +++ b/src/main/java/org/eclipsefoundation/git/eca/resource/GithubWebhooksResource.java @@ -26,7 +26,6 @@ import org.eclipsefoundation.git.eca.namespace.GitEcaParameterNames; import org.eclipsefoundation.git.eca.namespace.HCaptchaErrorCodes; import org.eclipsefoundation.git.eca.namespace.WebhookHeaders; import org.eclipsefoundation.git.eca.service.GithubApplicationService; -import org.eclipsefoundation.utils.helper.TransformationHelper; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -91,8 +90,8 @@ public class GithubWebhooksResource extends CommonResource { // track the request before we start processing GithubWebhookTracking tracking = validationHelper - .retrieveAndUpdateTrackingInformation(wrapper, request.getInstallation().getId(), request.getRepository().getFullName(), - pr); + .retrieveAndUpdateTrackingInformation(wrapper, request.getInstallation().getId(), + request.getRepository().getOwner().getLogin(), request.getRepository().getName(), pr); // start processing the request LOGGER.trace("Processing PR event for install {} with delivery ID of {}", request.getInstallation().getId(), deliveryId); @@ -129,13 +128,14 @@ public class GithubWebhooksResource extends CommonResource { */ @POST @Path("revalidate") - public Response revalidateWebhookRequest(@QueryParam(GitEcaParameterNames.REPOSITORY_FULL_NAME_RAW) String fullRepoName, + public Response revalidateWebhookRequest(@QueryParam(GitEcaParameterNames.REPOSITORY_NAME_RAW) String repoName, + @QueryParam(GitEcaParameterNames.ORG_NAME_RAW) String orgName, @QueryParam(GitEcaParameterNames.INSTALLATION_ID_RAW) String installationId, @QueryParam(GitEcaParameterNames.PULL_REQUEST_NUMBER_RAW) Integer prNo, @FormParam("h-captcha-response") String captchaResponse) { - String sanitizedRepoName = TransformationHelper.formatLog(fullRepoName); + String sanitizedRepoName = GithubValidationHelper.getFullRepoName(orgName, repoName); // retrieve and check that the PR exists - Optional<PullRequest> prResponse = ghAppService.getPullRequest(installationId, fullRepoName, prNo); + Optional<PullRequest> prResponse = ghAppService.getPullRequest(installationId, orgName, repoName, prNo); if (prResponse.isEmpty()) { throw new NotFoundException( String.format("Cannot find Github PR for repo '%s', pull request number '%d'", sanitizedRepoName, prNo)); @@ -143,7 +143,7 @@ public class GithubWebhooksResource extends CommonResource { // get the tracking if it exists, create it if it doesn't, and fail out if there is an issue GithubWebhookTracking tracking = validationHelper - .retrieveAndUpdateTrackingInformation(wrapper, installationId, fullRepoName, prResponse.get()); + .retrieveAndUpdateTrackingInformation(wrapper, installationId, orgName, repoName, prResponse.get()); if (tracking == null) { throw new ServerErrorException(String .format("Cannot find a tracked pull request with for repo '%s', pull request number '%d'", sanitizedRepoName, prNo), @@ -178,10 +178,7 @@ public class GithubWebhooksResource extends CommonResource { // build the url for pull request page StringBuilder sb = new StringBuilder(); - sb.append("https://github.com/"); - sb.append(fullRepoName); - sb.append("/pull/"); - sb.append(prNo); + sb.append("https://github.com/").append(orgName).append('/').append(repoName).append("/pull/").append(prNo); // respond with a URL to the new location in a standard request return Response.ok(RevalidationResponse.builder().setLocation(URI.create(sb.toString())).build()).build(); } catch (Exception e) { @@ -199,8 +196,8 @@ public class GithubWebhooksResource extends CommonResource { */ private ValidationRequest generateRequest(GithubWebhookRequest request, PullRequest pr) { return validationHelper - .generateRequest(request.getInstallation().getId(), request.getRepository().getFullName(), pr.getNumber(), - request.getRepository().getHtmlUrl()); + .generateRequest(request.getInstallation().getId(), request.getRepository().getOwner().getLogin(), + request.getRepository().getName(), pr.getNumber(), request.getRepository().getHtmlUrl()); } } diff --git a/src/main/java/org/eclipsefoundation/git/eca/resource/StatusResource.java b/src/main/java/org/eclipsefoundation/git/eca/resource/StatusResource.java index 65040e11703e20bf77974172977a6270240f5a26..ceeeab0cb903ce06b8eb10c7ca48dcc5255ba482 100644 --- a/src/main/java/org/eclipsefoundation/git/eca/resource/StatusResource.java +++ b/src/main/java/org/eclipsefoundation/git/eca/resource/StatusResource.java @@ -165,7 +165,7 @@ public class StatusResource extends CommonResource { } // get the data about the current request, and check that we have some validation statuses - ValidationRequest req = validationHelper.generateRequest(installationId, repoFullName, prNo, repoUrl); + ValidationRequest req = validationHelper.generateRequest(installationId, org, repoName, prNo, repoUrl); List<CommitValidationStatus> statuses = validationStatus .getHistoricValidationStatusByShas(wrapper, req.getCommits().stream().map(Commit::getHash).toList()); // check if we have any data, and if there is none, attempt to validate the request information diff --git a/src/main/java/org/eclipsefoundation/git/eca/service/GithubApplicationService.java b/src/main/java/org/eclipsefoundation/git/eca/service/GithubApplicationService.java index ae0a120f4c6ad886903f6c1d8183d974a65ec25c..67d0db4f1200eeb08dfb048c0824b238d902e2ae 100644 --- a/src/main/java/org/eclipsefoundation/git/eca/service/GithubApplicationService.java +++ b/src/main/java/org/eclipsefoundation/git/eca/service/GithubApplicationService.java @@ -45,9 +45,10 @@ public interface GithubApplicationService { * Retrieves a pull request given the repo, pull request, and associated installation to action the fetch. * * @param installationId installation ID to use when creating access tokens to query GH API - * @param repoFullName the full repo name, where the org and repo name are joined by a slash, e.g. eclipse/jetty + * @param repoFullName Github organization that owns the repo that holds the PR being validated + * @param repoName name of the repository within the organization that owns the PR * @param pullRequest the pull request numeric ID * @return the pull request if it exists, otherwise empty */ - Optional<PullRequest> getPullRequest(String installationId, String repoFullName, Integer pullRequest); + Optional<PullRequest> getPullRequest(String installationId, String org, String repoName, Integer pullRequest); } diff --git a/src/main/java/org/eclipsefoundation/git/eca/service/impl/DefaultGithubApplicationService.java b/src/main/java/org/eclipsefoundation/git/eca/service/impl/DefaultGithubApplicationService.java index d0603fc5794f6cb816f9a72026c91aab04130402..b575f69c30b173414dc767f8638f4d7ead047378 100644 --- a/src/main/java/org/eclipsefoundation/git/eca/service/impl/DefaultGithubApplicationService.java +++ b/src/main/java/org/eclipsefoundation/git/eca/service/impl/DefaultGithubApplicationService.java @@ -28,6 +28,7 @@ import org.eclipsefoundation.git.eca.api.GithubAPI; import org.eclipsefoundation.git.eca.api.models.GithubWebhookRequest.PullRequest; import org.eclipsefoundation.git.eca.config.WebhooksConfig; import org.eclipsefoundation.git.eca.dto.GithubApplicationInstallation; +import org.eclipsefoundation.git.eca.helper.GithubValidationHelper; import org.eclipsefoundation.git.eca.helper.JwtHelper; import org.eclipsefoundation.git.eca.namespace.GitEcaParameterNames; import org.eclipsefoundation.git.eca.service.GithubApplicationService; @@ -116,10 +117,11 @@ public class DefaultGithubApplicationService implements GithubApplicationService } @Override - public Optional<PullRequest> getPullRequest(String installationId, String repoFullName, Integer pullRequest) { + public Optional<PullRequest> getPullRequest(String installationId, String org, String repoName, Integer pullRequest) { + String fullRepoName = GithubValidationHelper.getFullRepoName(org, repoName); return cache - .get(repoFullName, new MultivaluedHashMap<>(), PullRequest.class, - () -> gh.getPullRequest(jwt.getGhBearerString(installationId), apiVersion, repoFullName, pullRequest)) + .get(fullRepoName, new MultivaluedHashMap<>(), PullRequest.class, + () -> gh.getPullRequest(jwt.getGhBearerString(installationId), apiVersion, org, repoName, pullRequest)) .getData(); } diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index e1cd86071dfe58b5a781c12429f9909cc38eda93..2a995ea9cdb4d98ea8a2e5fabfba00590cd10952 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -4,6 +4,7 @@ quarkus.http.port=8080 quarkus.http.root-path=/git quarkus.micrometer.enabled=true quarkus.thread-pool.max-threads=250 +quarkus.log.min-level=TRACE ## RestClient configs org.eclipsefoundation.git.eca.api.AccountsAPI/mp-rest/url=https://api.eclipse.org diff --git a/src/main/resources/templates/error.html b/src/main/resources/templates/error.html index db8549dd8130ae50beee70f4c13081b50971c99c..cb4032a3f6ee4f8670755d3c259790ce6b2ab407 100644 --- a/src/main/resources/templates/error.html +++ b/src/main/resources/templates/error.html @@ -1,4 +1,4 @@ -{#eclipse_base title='Git ECA Validation'} +{#eclipse_base title='Git ECA Validation' _unisolated} {#content_prewrap} {#include eclipse_breadcrumb /} <div class="container" id="main-page-content"> diff --git a/src/test/java/org/eclipsefoundation/git/eca/resource/GithubWebhooksResourceTest.java b/src/test/java/org/eclipsefoundation/git/eca/resource/GithubWebhooksResourceTest.java index 8f0b76e642f3d1776f25ebb2da039db647ca96e6..0c2943cf0fb797f04f8c2f191a2b870c9b1bac43 100644 --- a/src/test/java/org/eclipsefoundation/git/eca/resource/GithubWebhooksResourceTest.java +++ b/src/test/java/org/eclipsefoundation/git/eca/resource/GithubWebhooksResourceTest.java @@ -20,6 +20,7 @@ import org.eclipsefoundation.git.eca.api.models.GithubWebhookRequest.MergeGroup; import org.eclipsefoundation.git.eca.api.models.GithubWebhookRequest.PullRequest; import org.eclipsefoundation.git.eca.api.models.GithubWebhookRequest.PullRequestHead; import org.eclipsefoundation.git.eca.api.models.GithubWebhookRequest.Repository; +import org.eclipsefoundation.git.eca.api.models.GithubWebhookRequest.RepositoryOwner; import org.eclipsefoundation.git.eca.namespace.WebhookHeaders; import org.eclipsefoundation.http.exception.ApplicationException; import org.eclipsefoundation.testing.helpers.TestCaseHelper; @@ -80,6 +81,8 @@ class GithubWebhooksResourceTest { .setRepository(Repository .builder() .setFullName("eclipsefdn/sample") + .setName("sample") + .setOwner(RepositoryOwner.builder().setLogin("eclipsefdn").build()) .setHtmlUrl("http://www.github.com/eclipsefdn/sample") .build()) .build()); @@ -99,6 +102,8 @@ class GithubWebhooksResourceTest { .setRepository(Repository .builder() .setFullName("eclipsefdn/sample") + .setName("sample") + .setOwner(RepositoryOwner.builder().setLogin("eclipsefdn").build()) .setHtmlUrl("http://www.github.com/eclipsefdn/sample") .build()) .build()); diff --git a/src/test/java/org/eclipsefoundation/git/eca/test/api/MockGithubAPI.java b/src/test/java/org/eclipsefoundation/git/eca/test/api/MockGithubAPI.java index 4afea1712c664d6b6bcce0bff426c2cd64b049b1..7031f2d011f592ff731295737395743ff8749c9e 100644 --- a/src/test/java/org/eclipsefoundation/git/eca/test/api/MockGithubAPI.java +++ b/src/test/java/org/eclipsefoundation/git/eca/test/api/MockGithubAPI.java @@ -74,13 +74,14 @@ public class MockGithubAPI implements GithubAPI { } @Override - public PullRequest getPullRequest(String bearer, String apiVersion, String repoFull, int pullNumber) { + public PullRequest getPullRequest(String bearer, String apiVersion, String org, String repo, int pullNumber) { return PullRequest.builder().build(); } @Override - public RestResponse<List<GithubCommit>> getCommits(String bearer, String apiVersion, String repoFull, int pullNumber) { - List<GithubCommit> results = commits.get(repoFull).get(pullNumber); + public RestResponse<List<GithubCommit>> getCommits(String bearer, String apiVersion, String org, String repo, int pullNumber) { + String repoFullName = org + '/' + repo; + List<GithubCommit> results = commits.get(repoFullName).get(pullNumber); if (results == null || !results.isEmpty()) { return RestResponse.status(404); } @@ -88,9 +89,10 @@ public class MockGithubAPI implements GithubAPI { } @Override - public Response updateStatus(String bearer, String apiVersion, String repoFull, String prHeadSha, + public Response updateStatus(String bearer, String apiVersion, String org, String repo, String prHeadSha, GithubCommitStatusRequest commitStatusUpdate) { - commitStatuses.computeIfAbsent(repoFull, m -> new HashMap<>()).merge(prHeadSha, commitStatusUpdate.getState(), (k, v) -> v); + String repoFullName = org + '/' + repo; + commitStatuses.computeIfAbsent(repoFullName, m -> new HashMap<>()).merge(prHeadSha, commitStatusUpdate.getState(), (k, v) -> v); return Response.ok().build(); }