Skip to content

Commit 6576bea

Browse files
committed
Added missing methods to keep the API from breaking
added tests for addCollaborators()
1 parent 7916600 commit 6576bea

12 files changed

Lines changed: 713 additions & 0 deletions

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,4 @@ target
99
.DS_Store
1010

1111
dependency-reduced-pom.xml
12+
.factorypath

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

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -852,6 +852,30 @@ public void addCollaborators(GHOrganization.Permission perm, GHUser... users) th
852852
addCollaborators(perm, asList(users));
853853
}
854854

855+
/**
856+
* Add collaborators.
857+
*
858+
* @param users
859+
* the users
860+
* @throws IOException
861+
* the io exception
862+
*/
863+
public void addCollaborators(GHUser... users) throws IOException {
864+
addCollaborators(asList(users));
865+
}
866+
867+
/**
868+
* Add collaborators.
869+
*
870+
* @param users
871+
* the users
872+
* @throws IOException
873+
* the io exception
874+
*/
875+
public void addCollaborators(List<GHUser> users) throws IOException {
876+
modifyCollaborators(users, "PUT");
877+
}
878+
855879
/**
856880
* Add collaborators.
857881
*

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

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,23 @@ public void LatestRepositoryExist() {
158158
}
159159
}
160160

161+
@Test
162+
public void addCollaborators() throws Exception {
163+
GHRepository repo = getRepository();
164+
GHUser user = getUser();
165+
List<GHUser> users = new ArrayList<GHUser>();
166+
167+
users.add(user);
168+
repo.addCollaborators(GHOrganization.Permission.PUSH, users);
169+
170+
GHPersonSet<GHUser> collabs = repo.getCollaborators();
171+
172+
GHUser colabUser = collabs.byLogin(user.getLogin());
173+
174+
assertEquals(colabUser.getName(), user.getName());
175+
assertEquals(GHOrganization.Permission.PUSH, repo.getPermission(user.getName()));
176+
}
177+
161178
@Test
162179
public void LatestRepositoryNotExist() {
163180
try {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
{
2+
"login": "github-api-test-org",
3+
"id": 7544739,
4+
"node_id": "MDEyOk9yZ2FuaXphdGlvbjc1NDQ3Mzk=",
5+
"url": "https://api.github.com/orgs/github-api-test-org",
6+
"repos_url": "https://api.github.com/orgs/github-api-test-org/repos",
7+
"events_url": "https://api.github.com/orgs/github-api-test-org/events",
8+
"hooks_url": "https://api.github.com/orgs/github-api-test-org/hooks",
9+
"issues_url": "https://api.github.com/orgs/github-api-test-org/issues",
10+
"members_url": "https://api.github.com/orgs/github-api-test-org/members{/member}",
11+
"public_members_url": "https://api.github.com/orgs/github-api-test-org/public_members{/member}",
12+
"avatar_url": "https://avatars3.githubusercontent.com/u/7544739?v=4",
13+
"description": null,
14+
"is_verified": false,
15+
"has_organization_projects": true,
16+
"has_repository_projects": true,
17+
"public_repos": 10,
18+
"public_gists": 0,
19+
"followers": 0,
20+
"following": 0,
21+
"html_url": "https://github.com/github-api-test-org",
22+
"created_at": "2014-05-10T19:39:11Z",
23+
"updated_at": "2015-04-20T00:42:30Z",
24+
"type": "Organization"
25+
}

src/test/resources/org/kohsuke/github/GHRepositoryTest/wiremock/addCollaborators/__files/repos_github-api-test-org_github-api-e5504dd6-42ca-4d7f-9d95-f224e5f36a90.json

Lines changed: 328 additions & 0 deletions
Large diffs are not rendered by default.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
{
2+
"login": "jimmysombrero",
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:15:35Z",
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,45 @@
1+
{
2+
"id": "355d5cda-5423-49ef-b604-6276fbaba24e",
3+
"name": "orgs_github-api-test-org",
4+
"request": {
5+
"url": "/orgs/github-api-test-org",
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": "orgs_github-api-test-org-355d5cda-5423-49ef-b604-6276fbaba24e.json",
16+
"headers": {
17+
"Server": "GitHub.com",
18+
"Date": "Sun, 02 Feb 2020 04:29:45 GMT",
19+
"Content-Type": "application/json; charset=utf-8",
20+
"Status": "200 OK",
21+
"X-RateLimit-Limit": "5000",
22+
"X-RateLimit-Remaining": "4951",
23+
"X-RateLimit-Reset": "1580620984",
24+
"Cache-Control": "private, max-age=60, s-maxage=60",
25+
"Vary": "Accept, Authorization, Cookie, X-GitHub-OTP",
26+
"ETag": "W/\"7883ff712872fc993ac511231d8f8c6d\"",
27+
"Last-Modified": "Mon, 20 Apr 2015 00:42:30 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": "admin:org, read:org, repo, user, write:org",
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": "C7DB:0D8E:63D359:C9F18B:5E365038"
40+
}
41+
},
42+
"uuid": "355d5cda-5423-49ef-b604-6276fbaba24e",
43+
"persistent": true,
44+
"insertionIndex": 2
45+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
{
2+
"id": "e5504dd6-42ca-4d7f-9d95-f224e5f36a90",
3+
"name": "repos_github-api-test-org_github-api",
4+
"request": {
5+
"url": "/repos/github-api-test-org/github-api",
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": "repos_github-api-test-org_github-api-e5504dd6-42ca-4d7f-9d95-f224e5f36a90.json",
16+
"headers": {
17+
"Server": "GitHub.com",
18+
"Date": "Sun, 02 Feb 2020 04:29:45 GMT",
19+
"Content-Type": "application/json; charset=utf-8",
20+
"Status": "200 OK",
21+
"X-RateLimit-Limit": "5000",
22+
"X-RateLimit-Remaining": "4950",
23+
"X-RateLimit-Reset": "1580620984",
24+
"Cache-Control": "private, max-age=60, s-maxage=60",
25+
"Vary": "Accept, Authorization, Cookie, X-GitHub-OTP",
26+
"ETag": "W/\"c310cb7abd9a90e105810461c34dd8c6\"",
27+
"Last-Modified": "Thu, 16 Jan 2020 21:22:56 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": "repo",
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": "C7DB:0D8E:63D35D:C9F1A2:5E365039"
40+
}
41+
},
42+
"uuid": "e5504dd6-42ca-4d7f-9d95-f224e5f36a90",
43+
"persistent": true,
44+
"insertionIndex": 3
45+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
{
2+
"id": "1bfe0280-5533-459c-8515-57f70bed0d04",
3+
"name": "repos_github-api-test-org_github-api_collaborators_jimmysombrero",
4+
"request": {
5+
"url": "/repos/github-api-test-org/github-api/collaborators/jimmysombrero",
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": 404,
22+
"body": "{\"message\":\"Not Found\",\"documentation_url\":\"https://developer.github.com/v3/repos/collaborators/#add-user-as-a-collaborator\"}",
23+
"headers": {
24+
"Server": "GitHub.com",
25+
"Date": "Sun, 02 Feb 2020 04:29:45 GMT",
26+
"Content-Type": "application/json; charset=utf-8",
27+
"Status": "404 Not Found",
28+
"X-RateLimit-Limit": "5000",
29+
"X-RateLimit-Remaining": "4949",
30+
"X-RateLimit-Reset": "1580620984",
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": "C7DB:0D8E:63D367:C9F1B5:5E365039"
43+
}
44+
},
45+
"uuid": "1bfe0280-5533-459c-8515-57f70bed0d04",
46+
"persistent": true,
47+
"insertionIndex": 4
48+
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
{
2+
"id": "4533e6b8-1725-4450-97b1-895a776d49b7",
3+
"name": "user",
4+
"request": {
5+
"url": "/user",
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": "user-4533e6b8-1725-4450-97b1-895a776d49b7.json",
16+
"headers": {
17+
"Server": "GitHub.com",
18+
"Date": "Sun, 02 Feb 2020 04:29:44 GMT",
19+
"Content-Type": "application/json; charset=utf-8",
20+
"Status": "200 OK",
21+
"X-RateLimit-Limit": "5000",
22+
"X-RateLimit-Remaining": "4953",
23+
"X-RateLimit-Reset": "1580620983",
24+
"Cache-Control": "private, max-age=60, s-maxage=60",
25+
"Vary": "Accept, Authorization, Cookie, X-GitHub-OTP",
26+
"ETag": "W/\"275d33915a65ed3fa77d5fed34147440\"",
27+
"Last-Modified": "Sun, 02 Feb 2020 04:15:35 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": "C7DB:0D8E:63D34F:C9F17E:5E365038"
40+
}
41+
},
42+
"uuid": "4533e6b8-1725-4450-97b1-895a776d49b7",
43+
"persistent": true,
44+
"insertionIndex": 1
45+
}

0 commit comments

Comments
 (0)