Skip to content

Commit 64b555e

Browse files
authored
Merge branch 'main' into fix/JLL/project_card_repository
2 parents 02d88e8 + 0b8c6e3 commit 64b555e

18 files changed

+783
-24
lines changed

.github/workflows/maven-build.yml

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,14 @@ jobs:
1313
strategy:
1414
fail-fast: false
1515
matrix:
16-
java: [ 16 ]
16+
java: [ 16, 17 ]
1717
steps:
1818
- uses: actions/checkout@v2
1919
- name: Set up JDK
2020
uses: actions/setup-java@v2
2121
with:
2222
java-version: ${{ matrix.java }}
23-
distribution: 'adopt'
23+
distribution: 'zulu'
2424
- name: Cached .m2
2525
uses: actions/[email protected]
2626
with:
@@ -39,14 +39,14 @@ jobs:
3939
fail-fast: false
4040
matrix:
4141
os: [ ubuntu, windows ]
42-
java: [ 8, 11, 16 ]
42+
java: [ 8.0.192, 8, 11.0.3, 11, 16, 17 ]
4343
steps:
4444
- uses: actions/checkout@v2
4545
- name: Set up JDK
4646
uses: actions/setup-java@v2
4747
with:
4848
java-version: ${{ matrix.java }}
49-
distribution: 'adopt'
49+
distribution: 'zulu'
5050
- uses: actions/[email protected]
5151
with:
5252
path: ~/.m2/repository
@@ -55,22 +55,22 @@ jobs:
5555
${{ runner.os }}-maven-
5656
# JDK 8
5757
- name: Maven Install without Code Coverage
58-
if: matrix.os == 'windows' && matrix.java == '8'
58+
if: matrix.os == 'windows' && startsWith(matrix.java, '8')
5959
run: mvn -B clean install --file pom.xml
6060
- name: Maven Install with Code Coverage
61-
if: matrix.os != 'windows' && matrix.java == '8'
61+
if: matrix.os != 'windows' && startsWith(matrix.java, '8')
6262
run: mvn -B clean install -D enable-ci --file pom.xml
6363
- name: Codecov Report
64-
if: matrix.os != 'windows' && matrix.java == '8'
64+
if: matrix.os != 'windows' && startsWith(matrix.java, '8')
6565
uses: codecov/[email protected]
6666
# JDK 11+
6767
- name: Maven Install without Code Coverage
68-
if: matrix.os == 'windows' && matrix.java != '8'
68+
if: matrix.os == 'windows' && !startsWith(matrix.java, '8')
6969
env:
7070
MAVEN_OPTS: ${{ env.JAVA_11_PLUS_MAVEN_OPTS }}
7171
run: mvn -B clean install --file pom.xml "-Dsurefire.argLine=--add-opens java.base/java.net=ALL-UNNAMED"
7272
- name: Maven Install with Code Coverage
73-
if: matrix.os != 'windows' && matrix.java != '8'
73+
if: matrix.os != 'windows' && !startsWith(matrix.java, '8')
7474
env:
7575
MAVEN_OPTS: ${{ env.JAVA_11_PLUS_MAVEN_OPTS }}
7676
run: mvn -B clean install -D enable-ci --file pom.xml "-Dsurefire.argLine=--add-opens java.base/java.net=ALL-UNNAMED"

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,7 @@
319319
<plugin>
320320
<groupId>com.diffplug.spotless</groupId>
321321
<artifactId>spotless-maven-plugin</artifactId>
322-
<version>2.12.3</version>
322+
<version>2.15.0</version>
323323
<executions>
324324
<execution>
325325
<id>spotless-check</id>

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

Lines 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/main/java/org/kohsuke/github/GHRepository.java

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@
5757
import java.util.WeakHashMap;
5858

5959
import javax.annotation.Nonnull;
60+
import javax.annotation.Nullable;
6061

6162
import static java.util.Arrays.asList;
6263
import static java.util.Objects.requireNonNull;
@@ -3211,6 +3212,26 @@ public <T> T readTar(InputStreamFunction<T> streamFunction, String ref) throws I
32113212
return downloadArchive("tar", ref, streamFunction);
32123213
}
32133214

3215+
/**
3216+
* Create a repository dispatch event, which can be used to start a workflow/action from outside github, as
3217+
* described on https://docs.github.com/en/rest/reference/repos#create-a-repository-dispatch-event
3218+
*
3219+
* @param eventType
3220+
* the eventType
3221+
* @param clientPayload
3222+
* a custom payload , can be nullable
3223+
* @throws IOException
3224+
* the io exception
3225+
*/
3226+
public <T> void dispatch(String eventType, @Nullable T clientPayload) throws IOException {
3227+
root().createRequest()
3228+
.method("POST")
3229+
.withUrlPath(getApiTailUrl("dispatches"))
3230+
.with("event_type", eventType)
3231+
.with("client_payload", clientPayload)
3232+
.send();
3233+
}
3234+
32143235
private <T> T downloadArchive(@Nonnull String type,
32153236
@CheckForNull String ref,
32163237
@Nonnull InputStreamFunction<T> streamFunction) throws IOException {

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

Lines 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

Lines 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/java/org/kohsuke/github/GHRepositoryTest.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
import java.net.URL;
1414
import java.util.ArrayList;
1515
import java.util.Date;
16+
import java.util.HashMap;
1617
import java.util.List;
1718
import java.util.Map;
1819
import java.util.Set;
@@ -987,4 +988,19 @@ public void getCommitsBetweenPaged() throws Exception {
987988
assertThat(mockGitHub.getRequestCount(), equalTo(startingCount + 4));
988989
}
989990

991+
@Test
992+
public void createDispatchEventWithoutClientPayload() throws Exception {
993+
GHRepository repository = getTempRepository();
994+
repository.dispatch("test", null);
995+
}
996+
997+
@Test
998+
public void createDispatchEventWithClientPayload() throws Exception {
999+
GHRepository repository = getTempRepository();
1000+
Map<String, Object> clientPayload = new HashMap<>();
1001+
clientPayload.put("name", "joe.doe");
1002+
clientPayload.put("list", new ArrayList<>());
1003+
repository.dispatch("test", clientPayload);
1004+
}
1005+
9901006
}

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

Lines 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)