Skip to content

Commit 5726ceb

Browse files
authored
Merge branch 'master' into okhttp-close-responsebody
2 parents f5ad332 + c06c066 commit 5726ceb

19 files changed

Lines changed: 1329 additions & 18 deletions

CONTRIBUTING.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@ Example:
1414

1515
This the default behavior.
1616

17+
Example for a single test case:
18+
19+
`mvn install -Dtest=WireMockStatusReporterTest#user_whenProxying_AuthCorrectlyConfigured`
20+
1721

1822
### Setting up credential
1923

pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
<properties>
3535
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
3636
<spotbugs-maven-plugin.version>4.0.4</spotbugs-maven-plugin.version>
37-
<spotbugs.version>4.1.2</spotbugs.version>
37+
<spotbugs.version>4.1.3</spotbugs.version>
3838
<spotbugs-maven-plugin.failOnError>true</spotbugs-maven-plugin.failOnError>
3939
<hamcrest.version>2.2</hamcrest.version>
4040
<okhttp3.version>4.4.1</okhttp3.version>
@@ -537,7 +537,7 @@
537537
<dependency>
538538
<groupId>org.mockito</groupId>
539539
<artifactId>mockito-core</artifactId>
540-
<version>3.6.0</version>
540+
<version>3.6.28</version>
541541
<scope>test</scope>
542542
</dependency>
543543
<dependency>

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

Lines changed: 48 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -818,6 +818,13 @@ public int getSize() {
818818
return size;
819819
}
820820

821+
/**
822+
* Affiliation of a repository collaborator
823+
*/
824+
public enum CollaboratorAffiliation {
825+
ALL, DIRECT, OUTSIDE
826+
}
827+
821828
/**
822829
* Gets the collaborators on this repository. This set always appear to include the owner.
823830
*
@@ -841,6 +848,19 @@ public PagedIterable<GHUser> listCollaborators() throws IOException {
841848
return listUsers("collaborators");
842849
}
843850

851+
/**
852+
* Lists up the collaborators on this repository.
853+
*
854+
* @param affiliation
855+
* Filter users by affiliation
856+
* @return Users paged iterable
857+
* @throws IOException
858+
* the io exception
859+
*/
860+
public PagedIterable<GHUser> listCollaborators(CollaboratorAffiliation affiliation) throws IOException {
861+
return listUsers(root.createRequest().with("affiliation", affiliation), "collaborators");
862+
}
863+
844864
/**
845865
* Lists all
846866
* <a href="https://help.github.com/articles/assigning-issues-and-pull-requests-to-other-github-users/">the
@@ -888,6 +908,29 @@ public Set<String> getCollaboratorNames() throws IOException {
888908
return r;
889909
}
890910

911+
/**
912+
* Gets the names of the collaborators on this repository. This method deviates from the principle of this library
913+
* but it works a lot faster than {@link #getCollaborators()}.
914+
*
915+
* @param affiliation
916+
* Filter users by affiliation
917+
* @return the collaborator names
918+
* @throws IOException
919+
* the io exception
920+
*/
921+
public Set<String> getCollaboratorNames(CollaboratorAffiliation affiliation) throws IOException {
922+
Set<String> r = new HashSet<>();
923+
// no initializer - we just want to the logins
924+
PagedIterable<GHUser> users = root.createRequest()
925+
.withUrlPath(getApiTailUrl("collaborators"))
926+
.with("affiliation", affiliation)
927+
.toIterable(GHUser[].class, null);
928+
for (GHUser u : users.toArray()) {
929+
r.add(u.login);
930+
}
931+
return r;
932+
}
933+
891934
/**
892935
* Obtain permission for a given user in this repository.
893936
*
@@ -2092,9 +2135,11 @@ public PagedIterable<GHStargazer> listStargazers2() {
20922135
}
20932136

20942137
private PagedIterable<GHUser> listUsers(final String suffix) {
2095-
return root.createRequest()
2096-
.withUrlPath(getApiTailUrl(suffix))
2097-
.toIterable(GHUser[].class, item -> item.wrapUp(root));
2138+
return listUsers(root.createRequest(), suffix);
2139+
}
2140+
2141+
private PagedIterable<GHUser> listUsers(Requester requester, final String suffix) {
2142+
return requester.withUrlPath(getApiTailUrl(suffix)).toIterable(GHUser[].class, item -> item.wrapUp(root));
20982143
}
20992144

21002145
/**

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

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ private GitHubRequest(@Nonnull List<Entry> args,
7575

7676
/**
7777
* Create a new {@link Builder}.
78-
*
78+
*
7979
* @return a new {@link Builder}.
8080
*/
8181
public static Builder<?> newBuilder() {
@@ -165,7 +165,7 @@ public Map<String, Object> injectedMappingValues() {
165165

166166
/**
167167
* The base GitHub API URL for this request represented as a {@link String}
168-
*
168+
*
169169
* @return the url string
170170
*/
171171
@Nonnull
@@ -176,7 +176,7 @@ public String apiUrl() {
176176
/**
177177
* The url path to be added to the {@link #apiUrl()} for this request. If this does not start with a "/", it instead
178178
* represents the full url string for this request.
179-
*
179+
*
180180
* @return a url path or full url string
181181
*/
182182
@Nonnull
@@ -186,7 +186,7 @@ public String urlPath() {
186186

187187
/**
188188
* The content type to to be sent by this request.
189-
*
189+
*
190190
* @return the content type.
191191
*/
192192
@Nonnull
@@ -196,7 +196,7 @@ public String contentType() {
196196

197197
/**
198198
* The {@link InputStream} to be sent as the body of this request.
199-
*
199+
*
200200
* @return the {@link InputStream}.
201201
*/
202202
@CheckForNull
@@ -206,7 +206,7 @@ public InputStream body() {
206206

207207
/**
208208
* The {@link URL} for this request. This is the actual URL the {@link GitHubClient} will send this request to.
209-
*
209+
*
210210
* @return the request {@link URL}
211211
*/
212212
@Nonnull
@@ -216,7 +216,7 @@ public URL url() {
216216

217217
/**
218218
* Whether arguments for this request should be included in the URL or in the body of the request.
219-
*
219+
*
220220
* @return true if the arguements should be sent in the body of the request.
221221
*/
222222
public boolean inBody() {
@@ -226,7 +226,7 @@ public boolean inBody() {
226226
/**
227227
* Create a {@link Builder} from this request. Initial values of the builder will be the same as this
228228
* {@link GitHubRequest}.
229-
*
229+
*
230230
* @return a {@link Builder} based on this request.
231231
*/
232232
public Builder<?> toBuilder() {
@@ -346,7 +346,7 @@ private Builder(@Nonnull List<Entry> args,
346346

347347
/**
348348
* Builds a {@link GitHubRequest} from this builder.
349-
*
349+
*
350350
* @return a {@link GitHubRequest}
351351
* @throws MalformedURLException
352352
* if the GitHub API URL cannot be constructed
@@ -437,6 +437,21 @@ public B withPreview(String name) {
437437
return withHeader("Accept", name);
438438
}
439439

440+
/**
441+
* With requester.
442+
*
443+
* @param Map
444+
* map of key value pairs to add
445+
* @return the request builder
446+
*/
447+
public B with(Map<String, Object> map) {
448+
for (Map.Entry<String, Object> entry : map.entrySet()) {
449+
with(entry.getKey(), entry.getValue());
450+
}
451+
452+
return (B) this;
453+
}
454+
440455
/**
441456
* With requester.
442457
*

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -645,6 +645,15 @@ public void listCollaborators() throws Exception {
645645
assertThat(collaborators.size(), greaterThan(10));
646646
}
647647

648+
@Test
649+
public void listCollaboratorsFiltered() throws Exception {
650+
GHRepository repo = getRepository();
651+
List<GHUser> allCollaborators = repo.listCollaborators().toList();
652+
List<GHUser> filteredCollaborators = repo.listCollaborators(GHRepository.CollaboratorAffiliation.OUTSIDE)
653+
.toList();
654+
assertThat(filteredCollaborators.size(), lessThan(allCollaborators.size()));
655+
}
656+
648657
@Test
649658
public void getCheckRuns() throws Exception {
650659
final int expectedCount = 8;

src/test/resources/org/kohsuke/github/AppTest/wiremock/testMembership/mappings/repos_hub4j-test-org_jenkins_collaborators-4.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,4 +44,4 @@
4444
"uuid": "bce97482-6a11-44e5-a112-29230b142636",
4545
"persistent": true,
4646
"insertionIndex": 4
47-
}
47+
}

src/test/resources/org/kohsuke/github/GHRepositoryTest/wiremock/addCollaborators/mappings/repos_hub4j-test-org_github-api_collaborators-5-ddaa82.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,4 +38,4 @@
3838
"uuid": "ddaa8229-c0ae-4df6-90ed-08425bfe71f2",
3939
"persistent": true,
4040
"insertionIndex": 5
41-
}
41+
}

src/test/resources/org/kohsuke/github/GHRepositoryTest/wiremock/getCollaborators/mappings/repos_hub4j-test-org_github-api_collaborators-4.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,4 +44,4 @@
4444
"uuid": "2b8badfb-52b8-4304-a9a5-66b80274e93d",
4545
"persistent": true,
4646
"insertionIndex": 4
47-
}
47+
}

src/test/resources/org/kohsuke/github/GHRepositoryTest/wiremock/listCollaborators/mappings/repos_hub4j-test-org_github-api_collaborators-4.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,4 +44,4 @@
4444
"uuid": "b0680d17-cd3b-4ec0-a857-d352c7167e94",
4545
"persistent": true,
4646
"insertionIndex": 4
47-
}
47+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
{
2+
"login": "hub4j-test-org",
3+
"id": 7544739,
4+
"node_id": "MDEyOk9yZ2FuaXphdGlvbjc1NDQ3Mzk=",
5+
"url": "https://api.github.com/orgs/hub4j-test-org",
6+
"repos_url": "https://api.github.com/orgs/hub4j-test-org/repos",
7+
"events_url": "https://api.github.com/orgs/hub4j-test-org/events",
8+
"hooks_url": "https://api.github.com/orgs/hub4j-test-org/hooks",
9+
"issues_url": "https://api.github.com/orgs/hub4j-test-org/issues",
10+
"members_url": "https://api.github.com/orgs/hub4j-test-org/members{/member}",
11+
"public_members_url": "https://api.github.com/orgs/hub4j-test-org/public_members{/member}",
12+
"avatar_url": "https://avatars3.githubusercontent.com/u/7544739?v=4",
13+
"description": "Hub4j Test Org Description (this could be null or blank too)",
14+
"name": "Hub4j Test Org Name (this could be null or blank too)",
15+
"company": null,
16+
"blog": "https://hub4j.url.io/could/be/null",
17+
"location": "Hub4j Test Org Location (this could be null or blank too)",
18+
"email": "hub4jtestorgemail@could.be.null.com",
19+
"twitter_username": null,
20+
"is_verified": false,
21+
"has_organization_projects": true,
22+
"has_repository_projects": true,
23+
"public_repos": 13,
24+
"public_gists": 0,
25+
"followers": 0,
26+
"following": 0,
27+
"html_url": "https://github.com/hub4j-test-org",
28+
"created_at": "2014-05-10T19:39:11Z",
29+
"updated_at": "2020-06-04T05:56:10Z",
30+
"type": "Organization",
31+
"total_private_repos": 2,
32+
"owned_private_repos": 2,
33+
"private_gists": 0,
34+
"disk_usage": 152,
35+
"collaborators": 0,
36+
"billing_email": "kk@kohsuke.org",
37+
"default_repository_permission": "none",
38+
"members_can_create_repositories": false,
39+
"two_factor_requirement_enabled": false,
40+
"members_can_create_pages": true,
41+
"plan": {
42+
"name": "free",
43+
"space": 976562499,
44+
"private_repos": 10000,
45+
"filled_seats": 21,
46+
"seats": 3
47+
}
48+
}

0 commit comments

Comments
 (0)