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

Merge branch 'malowe/main/143' into 'main'

Iss #143 - Handle Status event by making PR in hook optional but checked

Closes #143

See merge request !160
parents f1452db3 a64cdb06
No related branches found
No related tags found
1 merge request!160Iss #143 - Handle Status event by making PR in hook optional but checked
Pipeline #32104 passed
......@@ -11,6 +11,8 @@
*/
package org.eclipsefoundation.git.eca.api.models;
import javax.annotation.Nullable;
import org.eclipsefoundation.git.eca.dto.GithubWebhookTracking;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
......@@ -31,6 +33,7 @@ public abstract class GithubWebhookRequest {
public abstract Repository getRepository();
@Nullable
public abstract PullRequest getPullRequest();
/**
......@@ -73,7 +76,7 @@ public abstract class GithubWebhookRequest {
public abstract Builder setRepository(Repository repository);
public abstract Builder setPullRequest(PullRequest pullRequest);
public abstract Builder setPullRequest(@Nullable PullRequest pullRequest);
public abstract GithubWebhookRequest build();
}
......
......@@ -27,6 +27,7 @@ import javax.ws.rs.QueryParam;
import javax.ws.rs.ServerErrorException;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.Response.Status;
import org.apache.http.HttpStatus;
import org.eclipsefoundation.core.helper.LoggingHelper;
......@@ -83,16 +84,22 @@ public class GithubWebhooksResource extends GithubAdjacentResource {
return Response.ok().build();
}
// check that the pull request isn't somehow missing
if (request.getPullRequest() == null) {
throw new BadRequestException("Pull request event submitted, but pull request information was missing");
}
PullRequest pr = request.getPullRequest();
// track the request before we start processing
GithubWebhookTracking tracking = validationHelper
.retrieveAndUpdateTrackingInformation(wrapper, request.getInstallation().getId(), request.getRepository().getFullName(),
request.getPullRequest());
pr);
// start processing the request
LOGGER.trace("Processing PR event for install {} with delivery ID of {}", request.getInstallation().getId(), deliveryId);
try {
// prepare for validation process by pre-processing into standard format
ValidationRequest vr = generateRequest(request);
ValidationRequest vr = generateRequest(request, pr);
// process the request
validationHelper.handleGithubWebhookValidation(request, vr, wrapper);
} catch (Exception e) {
......@@ -160,7 +167,13 @@ public class GithubWebhooksResource extends GithubAdjacentResource {
try {
// get the tracking class, convert back to a GH webhook request, and validate the request
GithubWebhookRequest request = GithubWebhookRequest.buildFromTracking(tracking);
boolean isSuccessful = validationHelper.handleGithubWebhookValidation(request, generateRequest(request), wrapper).getPassed();
if (request.getPullRequest() == null) {
throw new ServerErrorException("Current validation is in a bad state, pull request information missing",
Status.INTERNAL_SERVER_ERROR);
}
boolean isSuccessful = validationHelper
.handleGithubWebhookValidation(request, generateRequest(request, request.getPullRequest()), wrapper)
.getPassed();
LOGGER.debug("Revalidation for request for '{}#{}' was {}successful.", sanitizedRepoName, prNo, isSuccessful ? "" : " not");
// build the url for pull request page
......@@ -181,12 +194,13 @@ public class GithubWebhooksResource extends GithubAdjacentResource {
* Generate the validation request for the current GH Webhook request.
*
* @param request the current webhook request for validation
* @param pr null checked pull request from Github
* @return the Validation Request body to be used in validating data
*/
private ValidationRequest generateRequest(GithubWebhookRequest request) {
private ValidationRequest generateRequest(GithubWebhookRequest request, PullRequest pr) {
return validationHelper
.generateRequest(request.getInstallation().getId(), request.getRepository().getFullName(),
request.getPullRequest().getNumber(), request.getRepository().getHtmlUrl());
.generateRequest(request.getInstallation().getId(), request.getRepository().getFullName(), pr.getNumber(),
request.getRepository().getHtmlUrl());
}
}
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