Skip to content

Commit 5b15600

Browse files
committed
Add 'Preview' support for MergeMethod on GHPullRequest
- Add 'polaris' preview - Add MergeMethod Enum - Add merge method to GHPullRequest which takes a MergeMethod
1 parent 1f4325e commit 5b15600

3 files changed

Lines changed: 38 additions & 1 deletion

File tree

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

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323
*/
2424
package org.kohsuke.github;
2525

26+
import static org.kohsuke.github.Previews.POLARIS;
27+
2628
import java.io.IOException;
2729
import java.net.URL;
2830
import java.util.Collection;
@@ -277,7 +279,7 @@ public GHPullRequestReviewComment createReviewComment(String body, String sha, S
277279
* Commit message. If null, the default one will be used.
278280
*/
279281
public void merge(String msg) throws IOException {
280-
merge(msg,null);
282+
merge(msg,(String)null);
281283
}
282284

283285
/**
@@ -294,6 +296,27 @@ public void merge(String msg, String sha) throws IOException {
294296
new Requester(root).method("PUT").with("commit_message",msg).with("sha",sha).to(getApiRoute()+"/merge");
295297
}
296298

299+
/**
300+
* Merge this pull request, using the specified merge method.
301+
*
302+
* The equivalent of the big green "Merge pull request" button.
303+
*
304+
* @param msg
305+
* Commit message. If null, the default one will be used.
306+
* @param method
307+
* SHA that pull request head must match to allow merge.
308+
*/
309+
@Preview @Deprecated
310+
public void merge(String msg, MergeMethod method) throws IOException {
311+
new Requester(root).method("PUT")
312+
.withPreview(POLARIS)
313+
.with("commit_message",msg)
314+
.with("merge_method",method)
315+
.to(getApiRoute()+"/merge");
316+
}
317+
318+
public enum MergeMethod{ MERGE, SQUASH, REBASE }
319+
297320
private void fetchIssue() throws IOException {
298321
if (!fetchedIssueDetails) {
299322
new Requester(root).to(getIssuesApiRoute(), this);

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,5 @@
88
static final String DRAX = "application/vnd.github.drax-preview+json";
99
static final String SQUIRREL_GIRL = "application/vnd.github.squirrel-girl-preview";
1010
static final String KORRA = "application/vnd.github.korra-preview";
11+
static final String POLARIS = "application/vnd.github.polaris-preview";
1112
}

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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,19 @@ public void testMergeCommitSHA() throws Exception {
6969
fail();
7070
}
7171

72+
@Test
73+
public void testSquashMerge() throws Exception {
74+
String name = rnd.next();
75+
GHRef masterRef = getRepository().getRef("heads/master");
76+
GHRef branchRef = getRepository().createRef("refs/heads/" + name, masterRef.getObject().getSha());
77+
getRepository().createContent(name, name, name, name);
78+
Thread.sleep(1000);
79+
GHPullRequest p = getRepository().createPullRequest(name, name, "master", "## test squash");
80+
Thread.sleep(1000);
81+
p.merge("squash merge", GHPullRequest.MergeMethod.SQUASH);
82+
branchRef.delete();
83+
}
84+
7285
@Test
7386
// Requires push access to the test repo to pass
7487
public void setLabels() throws Exception {

0 commit comments

Comments
 (0)