Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 0567b4e

Browse filesBrowse files
authored
Merge pull request hub4j#1247 from jeskosda/feat/add_automerge_state
feat: add auto merge information to pull request
2 parents 8f3a100 + 1b5de5b commit 0567b4e
Copy full SHA for 0567b4e

File tree

Expand file treeCollapse file tree

4 files changed

+104
-14
lines changed
Filter options
Expand file treeCollapse file tree

4 files changed

+104
-14
lines changed

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

Copy file name to clipboardExpand all lines: src/main/java/org/kohsuke/github/GHPullRequest.java
+67-11Lines changed: 67 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,10 @@ public class GHPullRequest extends GHIssue implements Refreshable {
6868
private String mergeable_state;
6969
private int changed_files;
7070
private String merge_commit_sha;
71+
private AutoMerge auto_merge;
7172

7273
// pull request reviewers
74+
7375
private GHUser[] requested_reviewers;
7476
private GHTeam[] requested_teams;
7577

@@ -84,11 +86,19 @@ protected String getApiRoute() {
8486
// Issues returned from search to do not have an owner. Attempt to use url.
8587
final URL url = Objects.requireNonNull(getUrl(), "Missing instance URL!");
8688
return StringUtils.prependIfMissing(url.toString().replace(root().getApiUrl(), ""), "/");
87-
8889
}
8990
return "/repos/" + owner.getOwnerName() + "/" + owner.getName() + "/pulls/" + number;
9091
}
9192

93+
/**
94+
* The status of auto merging a pull request.
95+
*
96+
* @return the {@linkplain AutoMerge} or {@code null} if no auto merge is set.
97+
*/
98+
public AutoMerge getAutoMerge() {
99+
return auto_merge;
100+
}
101+
92102
/**
93103
* The URL of the patch file. like https://github.com/jenkinsci/jenkins/pull/100.patch
94104
*
@@ -268,9 +278,7 @@ public Boolean getMergeable() throws IOException {
268278
return mergeable;
269279
}
270280

271-
/**
272-
* for test purposes only
273-
*/
281+
/** for test purposes only */
274282
@Deprecated
275283
Boolean getMergeableNoRefresh() throws IOException {
276284
return mergeable;
@@ -351,6 +359,7 @@ public List<GHTeam> getRequestedTeams() throws IOException {
351359
/**
352360
* Fully populate the data by retrieving missing data.
353361
*
362+
* <p>
354363
* Depending on the original API call where this object is created, it may not contain everything.
355364
*/
356365
private void populate() throws IOException {
@@ -359,9 +368,7 @@ private void populate() throws IOException {
359368
refresh();
360369
}
361370

362-
/**
363-
* Repopulates this object.
364-
*/
371+
/** Repopulates this object. */
365372
public void refresh() throws IOException {
366373
if (isOffline()) {
367374
return; // cannot populate, will have to live with what we have
@@ -378,7 +385,6 @@ public void refresh() throws IOException {
378385
* default.
379386
*
380387
* @return the paged iterable
381-
*
382388
* @see <a href="https://docs.github.com/en/rest/reference/pulls#list-pull-requests-files">List pull requests
383389
* files</a>
384390
*/
@@ -577,6 +583,7 @@ public void updateBranch() throws IOException {
577583

578584
/**
579585
* Merge this pull request.
586+
*
580587
* <p>
581588
* The equivalent of the big green "Merge pull request" button.
582589
*
@@ -591,6 +598,7 @@ public void merge(String msg) throws IOException {
591598

592599
/**
593600
* Merge this pull request.
601+
*
594602
* <p>
595603
* The equivalent of the big green "Merge pull request" button.
596604
*
@@ -607,6 +615,7 @@ public void merge(String msg, String sha) throws IOException {
607615

608616
/**
609617
* Merge this pull request, using the specified merge method.
618+
*
610619
* <p>
611620
* The equivalent of the big green "Merge pull request" button.
612621
*
@@ -629,11 +638,58 @@ public void merge(String msg, String sha, MergeMethod method) throws IOException
629638
.send();
630639
}
631640

632-
/**
633-
* The enum MergeMethod.
634-
*/
641+
/** The enum MergeMethod. */
635642
public enum MergeMethod {
636643
MERGE, SQUASH, REBASE
637644
}
638645

646+
/**
647+
* The status of auto merging a {@linkplain GHPullRequest}.
648+
*
649+
*/
650+
@SuppressFBWarnings(value = "UWF_UNWRITTEN_FIELD", justification = "Field comes from JSON deserialization")
651+
public static class AutoMerge {
652+
653+
private GHUser enabled_by;
654+
private MergeMethod merge_method;
655+
private String commit_title;
656+
private String commit_message;
657+
658+
/**
659+
* The user who enabled the auto merge of the pull request.
660+
*
661+
* @return the {@linkplain GHUser}
662+
*/
663+
@SuppressFBWarnings(value = { "EI_EXPOSE_REP" }, justification = "Expected behavior")
664+
public GHUser getEnabledBy() {
665+
return enabled_by;
666+
}
667+
668+
/**
669+
* The merge method of the auto merge.
670+
*
671+
* @return the {@linkplain MergeMethod}
672+
*/
673+
public MergeMethod getMergeMethod() {
674+
return merge_method;
675+
}
676+
677+
/**
678+
* the title of the commit, if e.g. {@linkplain MergeMethod#SQUASH} is used for the auto merge.
679+
*
680+
* @return the title of the commit
681+
*/
682+
public String getCommitTitle() {
683+
return commit_title;
684+
}
685+
686+
/**
687+
* the message of the commit, if e.g. {@linkplain MergeMethod#SQUASH} is used for the auto merge.
688+
*
689+
* @return the message of the commit
690+
*/
691+
public String getCommitMessage() {
692+
return commit_message;
693+
}
694+
}
639695
}

‎src/test/java/org/kohsuke/github/EnumTest.java

Copy file name to clipboardExpand all lines: src/test/java/org/kohsuke/github/EnumTest.java
+2-1Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package org.kohsuke.github;
22

33
import org.junit.Test;
4+
import org.kohsuke.github.GHPullRequest.MergeMethod;
45

56
import static org.hamcrest.CoreMatchers.*;
67

@@ -55,7 +56,7 @@ public void touchEnums() {
5556
assertThat(GHProject.ProjectState.values().length, equalTo(2));
5657
assertThat(GHProject.ProjectStateFilter.values().length, equalTo(3));
5758

58-
assertThat(GHPullRequest.MergeMethod.values().length, equalTo(3));
59+
assertThat(MergeMethod.values().length, equalTo(3));
5960

6061
assertThat(GHPullRequestQueryBuilder.Sort.values().length, equalTo(4));
6162

‎src/test/java/org/kohsuke/github/GHPullRequestTest.java

Copy file name to clipboardExpand all lines: src/test/java/org/kohsuke/github/GHPullRequestTest.java
+9-1Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import org.junit.After;
44
import org.junit.Before;
55
import org.junit.Test;
6+
import org.kohsuke.github.GHPullRequest.AutoMerge;
67

78
import java.io.IOException;
89
import java.util.Collection;
@@ -37,6 +38,14 @@ public void createPullRequest() throws Exception {
3738
assertThat(p.getTitle(), equalTo(name));
3839
assertThat(p.canMaintainerModify(), is(false));
3940
assertThat(p.isDraft(), is(false));
41+
42+
// Check auto merge status of the pull request
43+
final AutoMerge autoMerge = p.getAutoMerge();
44+
assertThat(autoMerge, is(notNullValue()));
45+
assertThat(autoMerge.getCommitMessage(), equalTo("This is a auto merged squash commit message"));
46+
assertThat(autoMerge.getCommitTitle(), equalTo("This is a auto merged squash commit"));
47+
assertThat(autoMerge.getMergeMethod(), equalTo(GHPullRequest.MergeMethod.SQUASH));
48+
assertThat(autoMerge.getEnabledBy(), is(notNullValue()));
4049
}
4150

4251
@Test
@@ -60,7 +69,6 @@ public void createDraftPullRequest() throws Exception {
6069
p = repo.queryPullRequests().state(GHIssueState.OPEN).head("test/stable").list().toList().get(0);
6170
assertThat(p2.getNumber(), is(p.getNumber()));
6271
assertThat(p.isDraft(), is(true));
63-
6472
}
6573

6674
@Test

‎src/test/resources/org/kohsuke/github/GHPullRequestTest/wiremock/createPullRequest/__files/repos_hub4j-test-org_github-api_pulls-4.json

Copy file name to clipboardExpand all lines: src/test/resources/org/kohsuke/github/GHPullRequestTest/wiremock/createPullRequest/__files/repos_hub4j-test-org_github-api_pulls-4.json
+26-1Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -328,6 +328,31 @@
328328
"mergeable": null,
329329
"rebaseable": null,
330330
"mergeable_state": "unknown",
331+
"auto_merge": {
332+
"enabled_by": {
333+
"login": "bitwiseman",
334+
"id": 1958953,
335+
"node_id": "MDQ6VXNlcjE5NTg5NTM=",
336+
"avatar_url": "https://avatars3.githubusercontent.com/u/1958953?v=4",
337+
"gravatar_id": "",
338+
"url": "http://localhost:51456/users/bitwiseman",
339+
"html_url": "https://github.com/bitwiseman",
340+
"followers_url": "http://localhost:51456/users/bitwiseman/followers",
341+
"following_url": "http://localhost:51456/users/bitwiseman/following{/other_user}",
342+
"gists_url": "http://localhost:51456/users/bitwiseman/gists{/gist_id}",
343+
"starred_url": "http://localhost:51456/users/bitwiseman/starred{/owner}{/repo}",
344+
"subscriptions_url": "http://localhost:51456/users/bitwiseman/subscriptions",
345+
"organizations_url": "http://localhost:51456/users/bitwiseman/orgs",
346+
"repos_url": "http://localhost:51456/users/bitwiseman/repos",
347+
"events_url": "http://localhost:51456/users/bitwiseman/events{/privacy}",
348+
"received_events_url": "http://localhost:51456/users/bitwiseman/received_events",
349+
"type": "User",
350+
"site_admin": false
351+
},
352+
"merge_method": "squash",
353+
"commit_title": "This is a auto merged squash commit",
354+
"commit_message": "This is a auto merged squash commit message"
355+
},
331356
"merged_by": null,
332357
"comments": 0,
333358
"review_comments": 0,
@@ -336,4 +361,4 @@
336361
"additions": 1,
337362
"deletions": 1,
338363
"changed_files": 1
339-
}
364+
}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.