Skip to content

Commit 4abbaaa

Browse files
authored
fix: fix nullpointerexception when body is null (#390)
* fix: fix nullpointerexception when body is null An exception will occur when the body is null (empty) and a pr description check is configured. This change will fall back to an empty string when the body is null (and thus empty). * chore: add test case * fix: fixed newly added test case
1 parent f537d09 commit 4abbaaa

File tree

2 files changed

+22
-2
lines changed

2 files changed

+22
-2
lines changed

github-pullrequest-plugin/src/main/java/org/jenkinsci/plugins/github/pullrequest/events/impl/GitHubPRDescriptionEvent.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ public GitHubPRCause check(@NonNull GitHubPRDecisionContext prDecisionContext) t
5555

5656
GitHubPRCause cause = null;
5757

58-
String pullRequestBody = remotePR.getBody().trim();
58+
String pullRequestBody = remotePR.getBody() != null ? remotePR.getBody().trim() : "";
5959
LOG.debug("Job: '{}', trigger event: '{}', body for test: '{}'",
6060
fullName,
6161
DISPLAY_NAME,

github-pullrequest-plugin/src/test/java/org/jenkinsci/plugins/github/pullrequest/events/impl/GitHubPRDescriptionEventTest.java

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ public void skipDescriptionExist() throws IOException {
7474
}
7575

7676
@Test
77-
public void skipDescriptionNotExist() throws IOException {
77+
public void skipDescriptionExistNotMatch() throws IOException {
7878
commonExpectations();
7979
causeCreationExpectations();
8080

@@ -93,6 +93,26 @@ public void skipDescriptionNotExist() throws IOException {
9393
assertThat(cause, nullValue());
9494
}
9595

96+
@Test
97+
public void skipDescriptionNotExist() throws IOException {
98+
commonExpectations();
99+
causeCreationExpectations();
100+
101+
when(listener.getLogger()).thenReturn(logger);
102+
103+
when(remotePr.getBody()).thenReturn(null);
104+
105+
GitHubPRCause cause = new GitHubPRDescriptionEvent(".*[skip ci].*")
106+
.check(newGitHubPRDecisionContext()
107+
.withPrTrigger(trigger)
108+
.withRemotePR(remotePr)
109+
.withListener(listener)
110+
.build()
111+
);
112+
113+
assertThat(cause, nullValue());
114+
}
115+
96116
private void commonExpectations() throws IOException {
97117
when(parent.getFullName()).thenReturn("Full job name");
98118

0 commit comments

Comments
 (0)