Skip to content
Snippets Groups Projects
Commit c673bf88 authored by Martin Lowe's avatar Martin Lowe :flag_ca:
Browse files

Merge branch 'malowe/main/fix-gh-calls' into 'main'

fix: update GH API requests to handle rest client param encoding

See merge request !211
parents 1efaf0ae ff9147c3
No related branches found
No related tags found
1 merge request!211fix: update GH API requests to handle rest client param encoding
Pipeline #58567 passed
Showing
with 133 additions and 62 deletions
......@@ -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);
/**
......
......@@ -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 {
......
......@@ -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);
}
}
......@@ -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);
}
}
......@@ -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());
}
}
......@@ -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
......
......@@ -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);
}
......@@ -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();
}
......
......@@ -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
......
{#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">
......
......@@ -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());
......
......@@ -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();
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment