Skip to content

Commit

Permalink
Head branch is not sent for forks (#237)
Browse files Browse the repository at this point in the history
  • Loading branch information
timja authored Jan 15, 2022
1 parent 9efc8d6 commit f35f09a
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -76,12 +76,14 @@ protected Set<GHEvent> events() {
@SuppressFBWarnings(value = "BC_UNCONFIRMED_CAST_OF_RETURN_VALUE", justification = "Return value of parseEventPayload method is safe to cast.")
protected void onEvent(final GHSubscriberEvent event) {
final String payload = event.getPayload();
final String branchName;

try {
GHEventPayload.CheckRun checkRun = GitHub.offline().parseEventPayload(new StringReader(payload), GHEventPayload.CheckRun.class);
JSONObject payloadJSON = new JSONObject(payload);
branchName = payloadJSON.getJSONObject("check_run").getJSONObject("check_suite").getString("head_branch");
JSONObject checkSuite = payloadJSON.getJSONObject("check_run").getJSONObject("check_suite");
String branchName = null;
if (checkSuite.has("head_branch")) {
branchName = checkSuite.getString("head_branch");
}

if (!RERUN_ACTION.equals(checkRun.getAction())) {
LOGGER.log(Level.FINE,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ void shouldProcessCheckRunEventWithRerequestedAction() throws IOException {
@Test
void shouldThrowExceptionWhenCheckSuitesMissingFromPayload() throws IOException {
assertThatThrownBy(
() -> {
() -> {
new CheckRunGHEventSubscriber(mock(JenkinsFacade.class), mock(SCMFacade.class))
.onEvent(createEventWithRerunRequest(RERUN_REQUEST_JSON_FOR_PR_MISSING_CHECKSUITE));
})
Expand All @@ -84,14 +84,11 @@ void shouldThrowExceptionWhenCheckSuitesMissingFromPayload() throws IOException
}

@Test
void shouldThrowExceptionWhenHeadBranchMissingFromPayload() throws IOException {
assertThatThrownBy(
() -> {
new CheckRunGHEventSubscriber(mock(JenkinsFacade.class), mock(SCMFacade.class))
.onEvent(createEventWithRerunRequest(RERUN_REQUEST_JSON_FOR_PR_MISSING_CHECKSUITE_HEAD_BRANCH));
})
.isInstanceOf(IllegalStateException.class)
.hasMessageContaining("Could not parse check run event:");
void shouldIgnoreHeadBranchMissingFromPayload() throws IOException {
loggerRule.record(CheckRunGHEventSubscriber.class.getName(), Level.INFO).capture(1);
new CheckRunGHEventSubscriber(mock(JenkinsFacade.class), mock(SCMFacade.class))
.onEvent(createEventWithRerunRequest(RERUN_REQUEST_JSON_FOR_PR_MISSING_CHECKSUITE_HEAD_BRANCH));
assertThat(loggerRule.getMessages().get(0)).contains("Received rerun request through GitHub checks API.");
}

@Test
Expand Down

0 comments on commit f35f09a

Please sign in to comment.