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

Add support for MergeMethod on GHPullRequest #333

Merged
merged 3 commits into from
Sep 9, 2017
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
21 changes: 20 additions & 1 deletion src/main/java/org/kohsuke/github/GHPullRequest.java
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ public GHPullRequestReviewComment createReviewComment(String body, String sha, S
* Commit message. If null, the default one will be used.
*/
public void merge(String msg) throws IOException {
merge(msg,null);
merge(msg,(String)null);
}

/**
Expand All @@ -294,6 +294,25 @@ public void merge(String msg, String sha) throws IOException {
new Requester(root).method("PUT").with("commit_message",msg).with("sha",sha).to(getApiRoute()+"/merge");
}

/**
* Merge this pull request, using the specified merge method.
*
* The equivalent of the big green "Merge pull request" button.
*
* @param msg
* Commit message. If null, the default one will be used.
* @param method
* SHA that pull request head must match to allow merge.
*/
public void merge(String msg, MergeMethod method) throws IOException {
new Requester(root).method("PUT")
.with("commit_message",msg)
.with("merge_method",method)
.to(getApiRoute()+"/merge");
}

public enum MergeMethod{ MERGE, SQUASH, REBASE }

private void fetchIssue() throws IOException {
if (!fetchedIssueDetails) {
new Requester(root).to(getIssuesApiRoute(), this);
Expand Down
1 change: 1 addition & 0 deletions src/main/java/org/kohsuke/github/Previews.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@
static final String DRAX = "application/vnd.github.drax-preview+json";
static final String SQUIRREL_GIRL = "application/vnd.github.squirrel-girl-preview";
static final String KORRA = "application/vnd.github.korra-preview";
static final String POLARIS = "application/vnd.github.polaris-preview";
}
13 changes: 13 additions & 0 deletions src/test/java/org/kohsuke/github/PullRequestTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,19 @@ public void testMergeCommitSHA() throws Exception {
fail();
}

@Test
public void testSquashMerge() throws Exception {
String name = rnd.next();
GHRef masterRef = getRepository().getRef("heads/master");
GHRef branchRef = getRepository().createRef("refs/heads/" + name, masterRef.getObject().getSha());
getRepository().createContent(name, name, name, name);
Thread.sleep(1000);
GHPullRequest p = getRepository().createPullRequest(name, name, "master", "## test squash");
Thread.sleep(1000);
p.merge("squash merge", GHPullRequest.MergeMethod.SQUASH);
branchRef.delete();
}

@Test
// Requires push access to the test repo to pass
public void setLabels() throws Exception {
Expand Down