Skip to content

Commit ccfe3ad

Browse files
committed
Merge pull request hub4j#333
2 parents f721e05 + 9012820 commit ccfe3ad

3 files changed

Lines changed: 35 additions & 1 deletion

File tree

src/main/java/org/kohsuke/github/GHPullRequest.java

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -346,9 +346,29 @@ public void merge(String msg) throws IOException {
346346
* SHA that pull request head must match to allow merge.
347347
*/
348348
public void merge(String msg, String sha) throws IOException {
349-
new Requester(root).method("PUT").with("commit_message",msg).with("sha",sha).to(getApiRoute()+"/merge");
349+
merge(msg, sha, null);
350350
}
351351

352+
/**
353+
* Merge this pull request, using the specified merge method.
354+
*
355+
* The equivalent of the big green "Merge pull request" button.
356+
*
357+
* @param msg
358+
* Commit message. If null, the default one will be used.
359+
* @param method
360+
* SHA that pull request head must match to allow merge.
361+
*/
362+
public void merge(String msg, String sha, MergeMethod method) throws IOException {
363+
new Requester(root).method("PUT")
364+
.with("commit_message",msg)
365+
.with("sha",sha)
366+
.with("merge_method",method)
367+
.to(getApiRoute()+"/merge");
368+
}
369+
370+
public enum MergeMethod{ MERGE, SQUASH, REBASE }
371+
352372
private void fetchIssue() throws IOException {
353373
if (!fetchedIssueDetails) {
354374
new Requester(root).to(getIssuesApiRoute(), this);

src/main/java/org/kohsuke/github/extras/OkHttpConnector.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,3 +30,4 @@ public HttpURLConnection connect(URL url) throws IOException {
3030
return urlFactory.open(url);
3131
}
3232
}
33+
GHPul

src/test/java/org/kohsuke/github/PullRequestTest.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,19 @@ public void testMergeCommitSHA() throws Exception {
9999
fail();
100100
}
101101

102+
@Test
103+
public void testSquashMerge() throws Exception {
104+
String name = rnd.next();
105+
GHRef masterRef = getRepository().getRef("heads/master");
106+
GHRef branchRef = getRepository().createRef("refs/heads/" + name, masterRef.getObject().getSha());
107+
getRepository().createContent(name, name, name, name);
108+
Thread.sleep(1000);
109+
GHPullRequest p = getRepository().createPullRequest(name, name, "master", "## test squash");
110+
Thread.sleep(1000);
111+
p.merge("squash merge", null, GHPullRequest.MergeMethod.SQUASH);
112+
branchRef.delete();
113+
}
114+
102115
@Test
103116
// Requires push access to the test repo to pass
104117
public void setLabels() throws Exception {

0 commit comments

Comments
 (0)