Skip to content

Commit

Permalink
Merge pull request #333
Browse files Browse the repository at this point in the history
  • Loading branch information
kohsuke committed Sep 9, 2017
2 parents f721e05 + 9012820 commit ccfe3ad
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 1 deletion.
22 changes: 21 additions & 1 deletion src/main/java/org/kohsuke/github/GHPullRequest.java
Original file line number Diff line number Diff line change
Expand Up @@ -346,9 +346,29 @@ public void merge(String msg) throws IOException {
* SHA that pull request head must match to allow merge.
*/
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(msg, sha, null);
}

/**
* 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, String sha, MergeMethod method) throws IOException {
new Requester(root).method("PUT")
.with("commit_message",msg)
.with("sha",sha)
.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
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,4 @@ public HttpURLConnection connect(URL url) throws IOException {
return urlFactory.open(url);
}
}
GHPul
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 @@ -99,6 +99,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", null, GHPullRequest.MergeMethod.SQUASH);
branchRef.delete();
}

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

0 comments on commit ccfe3ad

Please sign in to comment.