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 9c7de76

Browse filesBrowse files
gastaldibitwiseman
authored andcommitted
Fixes modifyCollaborators for multiple users
Fixes hub4j#868
1 parent 8ba5cf7 commit 9c7de76
Copy full SHA for 9c7de76

File tree

Expand file treeCollapse file tree

5 files changed

+146
-7
lines changed
Filter options
Expand file treeCollapse file tree

5 files changed

+146
-7
lines changed

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

Copy file name to clipboardExpand all lines: src/main/java/org/kohsuke/github/GHRepository.java
+7-7Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
import java.util.HashMap;
4747
import java.util.HashSet;
4848
import java.util.Iterator;
49+
import java.util.LinkedHashSet;
4950
import java.util.List;
5051
import java.util.Map;
5152
import java.util.Objects;
@@ -979,13 +980,12 @@ public void removeCollaborators(Collection<GHUser> users) throws IOException {
979980
private void modifyCollaborators(@NonNull Collection<GHUser> users,
980981
@NonNull String method,
981982
@CheckForNull GHOrganization.Permission permission) throws IOException {
982-
Requester requester = root.createRequest().method(method);
983-
984-
if (permission != null) {
985-
requester = requester.with("permission", permission).inBody();
986-
}
987-
988-
for (GHUser user : users) {
983+
// Make sure that the users collection doesn't have any duplicates
984+
for (GHUser user : new LinkedHashSet<GHUser>(users)) {
985+
Requester requester = root.createRequest().method(method);
986+
if (permission != null) {
987+
requester = requester.with("permission", permission).inBody();
988+
}
989989
requester.withUrlPath(getApiTailUrl("collaborators/" + user.getLogin())).send();
990990
}
991991
}

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

Copy file name to clipboardExpand all lines: src/test/java/org/kohsuke/github/GHRepositoryTest.java
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,7 @@ public void addCollaborators() throws Exception {
191191
List<GHUser> users = new ArrayList<GHUser>();
192192

193193
users.add(user);
194+
users.add(gitHub.getUser("jimmysombrero2"));
194195
repo.addCollaborators(users, GHOrganization.Permission.PUSH);
195196

196197
GHPersonSet<GHUser> collabs = repo.getCollaborators();
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
{
2+
"login": "jimmysombrero2",
3+
"id": 12157727,
4+
"node_id": "MDQ6VXNlcjEyMTU3NzI3",
5+
"avatar_url": "https://avatars3.githubusercontent.com/u/12157727?v=4",
6+
"gravatar_id": "",
7+
"url": "https://api.github.com/users/jimmysombrero",
8+
"html_url": "https://github.com/jimmysombrero",
9+
"followers_url": "https://api.github.com/users/jimmysombrero/followers",
10+
"following_url": "https://api.github.com/users/jimmysombrero/following{/other_user}",
11+
"gists_url": "https://api.github.com/users/jimmysombrero/gists{/gist_id}",
12+
"starred_url": "https://api.github.com/users/jimmysombrero/starred{/owner}{/repo}",
13+
"subscriptions_url": "https://api.github.com/users/jimmysombrero/subscriptions",
14+
"organizations_url": "https://api.github.com/users/jimmysombrero/orgs",
15+
"repos_url": "https://api.github.com/users/jimmysombrero/repos",
16+
"events_url": "https://api.github.com/users/jimmysombrero/events{/privacy}",
17+
"received_events_url": "https://api.github.com/users/jimmysombrero/received_events",
18+
"type": "User",
19+
"site_admin": false,
20+
"name": null,
21+
"company": null,
22+
"blog": "",
23+
"location": null,
24+
"email": null,
25+
"hireable": null,
26+
"bio": null,
27+
"public_repos": 4,
28+
"public_gists": 0,
29+
"followers": 1,
30+
"following": 0,
31+
"created_at": "2015-04-28T17:47:19Z",
32+
"updated_at": "2020-02-02T04:43:58Z",
33+
"private_gists": 0,
34+
"total_private_repos": 0,
35+
"owned_private_repos": 0,
36+
"disk_usage": 19,
37+
"collaborators": 0,
38+
"two_factor_authentication": false,
39+
"plan": {
40+
"name": "free",
41+
"space": 976562499,
42+
"collaborators": 0,
43+
"private_repos": 10000
44+
}
45+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
{
2+
"id": "3d80b19e-05f4-4ad9-a610-5f573abc4363",
3+
"name": "repos_hub4j-test-org_github-api_collaborators_jimmysombrero2",
4+
"request": {
5+
"url": "/repos/hub4j-test-org/github-api/collaborators/jimmysombrero2",
6+
"method": "PUT",
7+
"headers": {
8+
"Accept": {
9+
"equalTo": "text/html, image/gif, image/jpeg, *; q=.2, */*; q=.2"
10+
}
11+
},
12+
"bodyPatterns": [
13+
{
14+
"equalToJson": "{\"permission\":\"push\"}",
15+
"ignoreArrayOrder": true,
16+
"ignoreExtraElements": true
17+
}
18+
]
19+
},
20+
"response": {
21+
"status": 201,
22+
"body": "[]",
23+
"headers": {
24+
"Server": "GitHub.com",
25+
"Date": "Sun, 02 Feb 2020 04:59:39 GMT",
26+
"Content-Type": "application/json; charset=utf-8",
27+
"Status": "201 Created",
28+
"X-RateLimit-Limit": "5000",
29+
"X-RateLimit-Remaining": "4892",
30+
"X-RateLimit-Reset": "1580620983",
31+
"X-OAuth-Scopes": "admin:enterprise, admin:gpg_key, admin:org, admin:org_hook, admin:public_key, admin:repo_hook, delete:packages, delete_repo, gist, notifications, read:packages, repo, user, workflow, write:discussion, write:packages",
32+
"X-Accepted-OAuth-Scopes": "",
33+
"X-GitHub-Media-Type": "unknown, github.v3",
34+
"Access-Control-Expose-Headers": "ETag, Link, Location, Retry-After, X-GitHub-OTP, X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Reset, X-OAuth-Scopes, X-Accepted-OAuth-Scopes, X-Poll-Interval, X-GitHub-Media-Type",
35+
"Access-Control-Allow-Origin": "*",
36+
"Strict-Transport-Security": "max-age=31536000; includeSubdomains; preload",
37+
"X-Frame-Options": "deny",
38+
"X-Content-Type-Options": "nosniff",
39+
"X-XSS-Protection": "1; mode=block",
40+
"Referrer-Policy": "origin-when-cross-origin, strict-origin-when-cross-origin",
41+
"Content-Security-Policy": "default-src 'none'",
42+
"X-GitHub-Request-Id": "C903:768E:16C4966:2BA11B0:5E36573B"
43+
}
44+
},
45+
"uuid": "3d80b19e-05f4-4ad9-a610-5f573abc4363",
46+
"persistent": true,
47+
"insertionIndex": 4
48+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
{
2+
"id": "6685376c-451b-486d-88cd-502af9a7c5d2",
3+
"name": "users_jimmysombrero2",
4+
"request": {
5+
"url": "/users/jimmysombrero2",
6+
"method": "GET",
7+
"headers": {
8+
"Accept": {
9+
"equalTo": "text/html, image/gif, image/jpeg, *; q=.2, */*; q=.2"
10+
}
11+
}
12+
},
13+
"response": {
14+
"status": 200,
15+
"bodyFileName": "users_jimmysombrero2.json",
16+
"headers": {
17+
"Server": "GitHub.com",
18+
"Date": "Mon, 03 Feb 2020 03:50:14 GMT",
19+
"Content-Type": "application/json; charset=utf-8",
20+
"Status": "200 OK",
21+
"X-RateLimit-Limit": "5000",
22+
"X-RateLimit-Remaining": "4907",
23+
"X-RateLimit-Reset": "1580704799",
24+
"Cache-Control": "private, max-age=60, s-maxage=60",
25+
"Vary": "Accept, Authorization, Cookie, X-GitHub-OTP",
26+
"ETag": "W/\"7a0206b47e995649c88218afeb2266a6\"",
27+
"Last-Modified": "Sun, 02 Feb 2020 04:43:58 GMT",
28+
"X-OAuth-Scopes": "admin:enterprise, admin:gpg_key, admin:org, admin:org_hook, admin:public_key, admin:repo_hook, delete:packages, delete_repo, gist, notifications, read:packages, repo, user, workflow, write:discussion, write:packages",
29+
"X-Accepted-OAuth-Scopes": "",
30+
"X-GitHub-Media-Type": "unknown, github.v3",
31+
"Access-Control-Expose-Headers": "ETag, Link, Location, Retry-After, X-GitHub-OTP, X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Reset, X-OAuth-Scopes, X-Accepted-OAuth-Scopes, X-Poll-Interval, X-GitHub-Media-Type",
32+
"Access-Control-Allow-Origin": "*",
33+
"Strict-Transport-Security": "max-age=31536000; includeSubdomains; preload",
34+
"X-Frame-Options": "deny",
35+
"X-Content-Type-Options": "nosniff",
36+
"X-XSS-Protection": "1; mode=block",
37+
"Referrer-Policy": "origin-when-cross-origin, strict-origin-when-cross-origin",
38+
"Content-Security-Policy": "default-src 'none'",
39+
"X-GitHub-Request-Id": "CDFE:768D:1021273:26DC788:5E379876"
40+
}
41+
},
42+
"uuid": "6685376c-451b-486d-88cd-502af9a7c5d1",
43+
"persistent": true,
44+
"insertionIndex": 6
45+
}

0 commit comments

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