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 fab5137

Browse filesBrowse files
authored
Merge pull request hub4j#1438 from gsmet/fix-team-remove
Fix GHTeam#remove(GHUser) and add tests
2 parents 474da8a + d870d21 commit fab5137
Copy full SHA for fab5137
Expand file treeCollapse file tree

20 files changed

+875
-2
lines changed

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

Copy file name to clipboardExpand all lines: src/main/java/org/kohsuke/github/GHTeam.java
+16-1Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313

1414
import javax.annotation.Nonnull;
1515

16+
import static org.kohsuke.github.GitHubRequest.transformEnum;
17+
1618
/**
1719
* A team in GitHub organization.
1820
*
@@ -151,6 +153,19 @@ public PagedIterable<GHUser> listMembers(String role) throws IOException {
151153
return root().createRequest().withUrlPath(api("/members")).with("role", role).toIterable(GHUser[].class, null);
152154
}
153155

156+
/**
157+
* List members with specified role paged iterable.
158+
*
159+
* @param role
160+
* the role
161+
* @return the paged iterable
162+
* @throws IOException
163+
* the io exception
164+
*/
165+
public PagedIterable<GHUser> listMembers(Role role) throws IOException {
166+
return listMembers(transformEnum(role));
167+
}
168+
154169
/**
155170
* Gets a single discussion by ID.
156171
*
@@ -288,7 +303,7 @@ public void add(GHUser user, Role role) throws IOException {
288303
* the io exception
289304
*/
290305
public void remove(GHUser u) throws IOException {
291-
root().createRequest().method("DELETE").withUrlPath(api("/members/" + u.getLogin())).send();
306+
root().createRequest().method("DELETE").withUrlPath(api("/memberships/" + u.getLogin())).send();
292307
}
293308

294309
/**

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

Copy file name to clipboardExpand all lines: src/test/java/org/kohsuke/github/GHTeamTest.java
+69-1Lines changed: 69 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,18 @@
22

33
import org.junit.Test;
44
import org.kohsuke.github.GHTeam.Privacy;
5+
import org.kohsuke.github.GHTeam.Role;
56

67
import java.io.IOException;
78
import java.util.List;
89
import java.util.Set;
910

10-
import static org.hamcrest.Matchers.*;
11+
import static org.hamcrest.Matchers.containsInAnyOrder;
12+
import static org.hamcrest.Matchers.empty;
13+
import static org.hamcrest.Matchers.equalTo;
14+
import static org.hamcrest.Matchers.hasProperty;
15+
import static org.hamcrest.Matchers.is;
16+
import static org.hamcrest.Matchers.notNullValue;
1117

1218
public class GHTeamTest extends AbstractGitHubWireMockTest {
1319

@@ -137,4 +143,66 @@ public void testFetchEmptyChildTeams() throws IOException {
137143
assertThat(result, is(empty()));
138144
}
139145

146+
@Test
147+
public void addRemoveMember() throws IOException {
148+
String teamSlug = "dummy-team";
149+
150+
GHTeam team = gitHub.getOrganization(GITHUB_API_TEST_ORG).getTeamBySlug(teamSlug);
151+
152+
List<GHUser> members = team.listMembers().toList();
153+
154+
assertThat(members, notNullValue());
155+
assertThat("One admin in dummy team", members.size(), equalTo(1));
156+
assertThat("Specific user in admin team",
157+
members.stream().anyMatch(ghUser -> ghUser.getLogin().equals("bitwiseman")));
158+
159+
GHUser user = gitHub.getUser("gsmet");
160+
161+
try {
162+
team.add(user, Role.MAINTAINER);
163+
164+
// test all
165+
members = team.listMembers().toList();
166+
167+
assertThat(members, notNullValue());
168+
assertThat("Two members for all roles in dummy team", members.size(), equalTo(2));
169+
assertThat("Specific users in team",
170+
members,
171+
containsInAnyOrder(hasProperty("login", equalTo("bitwiseman")),
172+
hasProperty("login", equalTo("gsmet"))));
173+
174+
// test maintainer role filter
175+
members = team.listMembers(Role.MAINTAINER).toList();
176+
177+
assertThat(members, notNullValue());
178+
assertThat("Two members for all roles in dummy team", members.size(), equalTo(2));
179+
assertThat("Specific users in team",
180+
members,
181+
containsInAnyOrder(hasProperty("login", equalTo("bitwiseman")),
182+
hasProperty("login", equalTo("gsmet"))));
183+
184+
// test member role filter
185+
// it's hard to test this as owner of the org are automatically made maintainer
186+
// so let's just test that we don't have any members around
187+
members = team.listMembers(Role.MEMBER).toList();
188+
189+
assertThat(members, notNullValue());
190+
assertThat("No members in dummy team", members.size(), equalTo(0));
191+
192+
// test removing the user has effect
193+
team.remove(user);
194+
195+
members = team.listMembers().toList();
196+
197+
assertThat(members, notNullValue());
198+
assertThat("One member for all roles in dummy team", members.size(), equalTo(1));
199+
assertThat("Specific user in team",
200+
members,
201+
containsInAnyOrder(hasProperty("login", equalTo("bitwiseman"))));
202+
} finally {
203+
if (team.hasMember(user)) {
204+
team.remove(user);
205+
}
206+
}
207+
}
140208
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
[
2+
{
3+
"login": "bitwiseman",
4+
"id": 1958953,
5+
"node_id": "MDQ6VXNlcjE5NTg5NTM=",
6+
"avatar_url": "https://avatars.githubusercontent.com/u/1958953?v=4",
7+
"gravatar_id": "",
8+
"url": "https://api.github.com/users/bitwiseman",
9+
"html_url": "https://github.com/bitwiseman",
10+
"followers_url": "https://api.github.com/users/bitwiseman/followers",
11+
"following_url": "https://api.github.com/users/bitwiseman/following{/other_user}",
12+
"gists_url": "https://api.github.com/users/bitwiseman/gists{/gist_id}",
13+
"starred_url": "https://api.github.com/users/bitwiseman/starred{/owner}{/repo}",
14+
"subscriptions_url": "https://api.github.com/users/bitwiseman/subscriptions",
15+
"organizations_url": "https://api.github.com/users/bitwiseman/orgs",
16+
"repos_url": "https://api.github.com/users/bitwiseman/repos",
17+
"events_url": "https://api.github.com/users/bitwiseman/events{/privacy}",
18+
"received_events_url": "https://api.github.com/users/bitwiseman/received_events",
19+
"type": "User",
20+
"site_admin": false
21+
}
22+
]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
[
2+
{
3+
"login": "bitwiseman",
4+
"id": 1958953,
5+
"node_id": "MDQ6VXNlcjE5NTg5NTM=",
6+
"avatar_url": "https://avatars.githubusercontent.com/u/1958953?v=4",
7+
"gravatar_id": "",
8+
"url": "https://api.github.com/users/bitwiseman",
9+
"html_url": "https://github.com/bitwiseman",
10+
"followers_url": "https://api.github.com/users/bitwiseman/followers",
11+
"following_url": "https://api.github.com/users/bitwiseman/following{/other_user}",
12+
"gists_url": "https://api.github.com/users/bitwiseman/gists{/gist_id}",
13+
"starred_url": "https://api.github.com/users/bitwiseman/starred{/owner}{/repo}",
14+
"subscriptions_url": "https://api.github.com/users/bitwiseman/subscriptions",
15+
"organizations_url": "https://api.github.com/users/bitwiseman/orgs",
16+
"repos_url": "https://api.github.com/users/bitwiseman/repos",
17+
"events_url": "https://api.github.com/users/bitwiseman/events{/privacy}",
18+
"received_events_url": "https://api.github.com/users/bitwiseman/received_events",
19+
"type": "User",
20+
"site_admin": false
21+
}
22+
]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
[
2+
{
3+
"login": "gsmet",
4+
"id": 1279749,
5+
"node_id": "MDQ6VXNlcjEyNzk3NDk=",
6+
"avatar_url": "https://avatars.githubusercontent.com/u/1279749?u=e462a6165ea17647aed446ca31fae604338ae18c&v=4",
7+
"gravatar_id": "",
8+
"url": "https://api.github.com/users/gsmet",
9+
"html_url": "https://github.com/gsmet",
10+
"followers_url": "https://api.github.com/users/gsmet/followers",
11+
"following_url": "https://api.github.com/users/gsmet/following{/other_user}",
12+
"gists_url": "https://api.github.com/users/gsmet/gists{/gist_id}",
13+
"starred_url": "https://api.github.com/users/gsmet/starred{/owner}{/repo}",
14+
"subscriptions_url": "https://api.github.com/users/gsmet/subscriptions",
15+
"organizations_url": "https://api.github.com/users/gsmet/orgs",
16+
"repos_url": "https://api.github.com/users/gsmet/repos",
17+
"events_url": "https://api.github.com/users/gsmet/events{/privacy}",
18+
"received_events_url": "https://api.github.com/users/gsmet/received_events",
19+
"type": "User",
20+
"site_admin": false
21+
},
22+
{
23+
"login": "bitwiseman",
24+
"id": 1958953,
25+
"node_id": "MDQ6VXNlcjE5NTg5NTM=",
26+
"avatar_url": "https://avatars.githubusercontent.com/u/1958953?v=4",
27+
"gravatar_id": "",
28+
"url": "https://api.github.com/users/bitwiseman",
29+
"html_url": "https://github.com/bitwiseman",
30+
"followers_url": "https://api.github.com/users/bitwiseman/followers",
31+
"following_url": "https://api.github.com/users/bitwiseman/following{/other_user}",
32+
"gists_url": "https://api.github.com/users/bitwiseman/gists{/gist_id}",
33+
"starred_url": "https://api.github.com/users/bitwiseman/starred{/owner}{/repo}",
34+
"subscriptions_url": "https://api.github.com/users/bitwiseman/subscriptions",
35+
"organizations_url": "https://api.github.com/users/bitwiseman/orgs",
36+
"repos_url": "https://api.github.com/users/bitwiseman/repos",
37+
"events_url": "https://api.github.com/users/bitwiseman/events{/privacy}",
38+
"received_events_url": "https://api.github.com/users/bitwiseman/received_events",
39+
"type": "User",
40+
"site_admin": false
41+
}
42+
]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
[
2+
{
3+
"login": "gsmet",
4+
"id": 1279749,
5+
"node_id": "MDQ6VXNlcjEyNzk3NDk=",
6+
"avatar_url": "https://avatars.githubusercontent.com/u/1279749?u=e462a6165ea17647aed446ca31fae604338ae18c&v=4",
7+
"gravatar_id": "",
8+
"url": "https://api.github.com/users/gsmet",
9+
"html_url": "https://github.com/gsmet",
10+
"followers_url": "https://api.github.com/users/gsmet/followers",
11+
"following_url": "https://api.github.com/users/gsmet/following{/other_user}",
12+
"gists_url": "https://api.github.com/users/gsmet/gists{/gist_id}",
13+
"starred_url": "https://api.github.com/users/gsmet/starred{/owner}{/repo}",
14+
"subscriptions_url": "https://api.github.com/users/gsmet/subscriptions",
15+
"organizations_url": "https://api.github.com/users/gsmet/orgs",
16+
"repos_url": "https://api.github.com/users/gsmet/repos",
17+
"events_url": "https://api.github.com/users/gsmet/events{/privacy}",
18+
"received_events_url": "https://api.github.com/users/gsmet/received_events",
19+
"type": "User",
20+
"site_admin": false
21+
},
22+
{
23+
"login": "bitwiseman",
24+
"id": 1958953,
25+
"node_id": "MDQ6VXNlcjE5NTg5NTM=",
26+
"avatar_url": "https://avatars.githubusercontent.com/u/1958953?v=4",
27+
"gravatar_id": "",
28+
"url": "https://api.github.com/users/bitwiseman",
29+
"html_url": "https://github.com/bitwiseman",
30+
"followers_url": "https://api.github.com/users/bitwiseman/followers",
31+
"following_url": "https://api.github.com/users/bitwiseman/following{/other_user}",
32+
"gists_url": "https://api.github.com/users/bitwiseman/gists{/gist_id}",
33+
"starred_url": "https://api.github.com/users/bitwiseman/starred{/owner}{/repo}",
34+
"subscriptions_url": "https://api.github.com/users/bitwiseman/subscriptions",
35+
"organizations_url": "https://api.github.com/users/bitwiseman/orgs",
36+
"repos_url": "https://api.github.com/users/bitwiseman/repos",
37+
"events_url": "https://api.github.com/users/bitwiseman/events{/privacy}",
38+
"received_events_url": "https://api.github.com/users/bitwiseman/received_events",
39+
"type": "User",
40+
"site_admin": false
41+
}
42+
]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
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://avatars.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": 49,
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": 4,
32+
"owned_private_repos": 4,
33+
"private_gists": 0,
34+
"disk_usage": 11979,
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_allowed_repository_creation_type": "none",
41+
"members_can_create_public_repositories": false,
42+
"members_can_create_private_repositories": false,
43+
"members_can_create_internal_repositories": false,
44+
"members_can_create_pages": true,
45+
"members_can_fork_private_repositories": false,
46+
"members_can_create_public_pages": true,
47+
"members_can_create_private_pages": true,
48+
"plan": {
49+
"name": "free",
50+
"space": 976562499,
51+
"private_repos": 10000,
52+
"filled_seats": 37,
53+
"seats": 3
54+
}
55+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
{
2+
"name": "dummy-team",
3+
"id": 3451996,
4+
"node_id": "MDQ6VGVhbTM0NTE5OTY=",
5+
"slug": "dummy-team",
6+
"description": "Updated by API TestModified",
7+
"privacy": "closed",
8+
"url": "https://api.github.com/organizations/7544739/team/3451996",
9+
"html_url": "https://github.com/orgs/hub4j-test-org/teams/dummy-team",
10+
"members_url": "https://api.github.com/organizations/7544739/team/3451996/members{/member}",
11+
"repositories_url": "https://api.github.com/organizations/7544739/team/3451996/repos",
12+
"permission": "pull",
13+
"created_at": "2019-10-03T21:46:12Z",
14+
"updated_at": "2022-03-04T10:36:59Z",
15+
"members_count": 1,
16+
"repos_count": 1,
17+
"organization": {
18+
"login": "hub4j-test-org",
19+
"id": 7544739,
20+
"node_id": "MDEyOk9yZ2FuaXphdGlvbjc1NDQ3Mzk=",
21+
"url": "https://api.github.com/orgs/hub4j-test-org",
22+
"repos_url": "https://api.github.com/orgs/hub4j-test-org/repos",
23+
"events_url": "https://api.github.com/orgs/hub4j-test-org/events",
24+
"hooks_url": "https://api.github.com/orgs/hub4j-test-org/hooks",
25+
"issues_url": "https://api.github.com/orgs/hub4j-test-org/issues",
26+
"members_url": "https://api.github.com/orgs/hub4j-test-org/members{/member}",
27+
"public_members_url": "https://api.github.com/orgs/hub4j-test-org/public_members{/member}",
28+
"avatar_url": "https://avatars.githubusercontent.com/u/7544739?v=4",
29+
"description": "Hub4j Test Org Description (this could be null or blank too)",
30+
"name": "Hub4j Test Org Name (this could be null or blank too)",
31+
"company": null,
32+
"blog": "https://hub4j.url.io/could/be/null",
33+
"location": "Hub4j Test Org Location (this could be null or blank too)",
34+
"email": "hub4jtestorgemail@could.be.null.com",
35+
"twitter_username": null,
36+
"is_verified": false,
37+
"has_organization_projects": true,
38+
"has_repository_projects": true,
39+
"public_repos": 49,
40+
"public_gists": 0,
41+
"followers": 0,
42+
"following": 0,
43+
"html_url": "https://github.com/hub4j-test-org",
44+
"created_at": "2014-05-10T19:39:11Z",
45+
"updated_at": "2020-06-04T05:56:10Z",
46+
"type": "Organization"
47+
},
48+
"parent": null
49+
}

0 commit comments

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