Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Head branch is not sent for forks #237

Merged
merged 1 commit into from
Jan 15, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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