Skip to content

Commit 320b075

Browse files
ExtendedPullRequestService.java
- don't set merge parameter if they are null, reported by @figaw in issue 38 PullRequestGroovyObject.java - added an overloaded merge() to match the README.md, reported by @figaw in issue 38 - switched to Optional usage in merge()
1 parent 8b35847 commit 320b075

File tree

2 files changed

+21
-8
lines changed

2 files changed

+21
-8
lines changed

src/main/java/org/jenkinsci/plugins/pipeline/github/PullRequestGroovyObject.java

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -649,10 +649,15 @@ public void deleteComment(final long commentId) {
649649

650650
@Whitelisted
651651
public String merge(final Map<String, Object> params) {
652-
return merge(params.get("commitTitle") != null ? params.get("commitTitle").toString() : null,
653-
params.get("commitMessage") != null ? params.get("commitMessage").toString() : null,
654-
params.get("sha") != null ? params.get("sha").toString() : null,
655-
params.get("mergeMethod") != null ? params.get("mergeMethod").toString() : null);
652+
return merge(Optional.ofNullable(params.get("commitTitle")).map(Object::toString).orElse(null),
653+
Optional.ofNullable(params.get("commitMessage")).map(Object::toString).orElse(null),
654+
Optional.ofNullable(params.get("sha")).map(Object::toString).orElse(null),
655+
Optional.ofNullable(params.get("mergeMethod")).map(Object::toString).orElse(null));
656+
}
657+
658+
@Whitelisted
659+
public String merge(final String commitMessage) {
660+
return merge(null, commitMessage, null, null);
656661
}
657662

658663
@Whitelisted

src/main/java/org/jenkinsci/plugins/pipeline/github/client/ExtendedPullRequestService.java

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -93,10 +93,18 @@ public ExtendedMergeStatus merge(final IRepositoryIdProvider repository,
9393
uri.append("/merge");
9494

9595
Map<String, String> params = new HashMap<>();
96-
params.put("commit_title", commitTitle);
97-
params.put("commit_message", commitMessage);
98-
params.put("sha", sha);
99-
params.put("merge_method", mergeMethod);
96+
if (commitTitle != null) {
97+
params.put("commit_title", commitTitle);
98+
}
99+
if (commitMessage != null) {
100+
params.put("commit_message", commitMessage);
101+
}
102+
if (sha != null) {
103+
params.put("sha", sha);
104+
}
105+
if (mergeMethod != null) {
106+
params.put("merge_method", mergeMethod);
107+
}
100108
return getClient().put(uri.toString(), params, ExtendedMergeStatus.class);
101109
}
102110

0 commit comments

Comments
 (0)