Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

List team members by role #950

Merged
merged 3 commits into from
Nov 5, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion src/main/java/org/kohsuke/github/GHTeam.java
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,22 @@ public PagedIterable<GHDiscussion> listDiscussions() throws IOException {
return GHDiscussion.readAll(this);
}

/**
* List members with specified role paged iterable.
*
* @param role
* the role
* @return the paged iterable
* @throws IOException
* the io exception
*/
public PagedIterable<GHUser> listMembers(String role) throws IOException {
return root.createRequest()
.withUrlPath(api("/members"))
.with("role", role)
.toIterable(GHUser[].class, item -> item.wrapUp(root));
}

/**
* Gets a single discussion by ID.
*
Expand All @@ -171,7 +187,7 @@ public GHDiscussion getDiscussion(long discussionNumber) throws IOException {
* the io exception
*/
public PagedIterable<GHUser> listMembers() throws IOException {
return root.createRequest().withUrlPath(api("/members")).toIterable(GHUser[].class, item -> item.wrapUp(root));
return listMembers("all");
}

/**
Expand Down
26 changes: 26 additions & 0 deletions src/test/java/org/kohsuke/github/GHTeamTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import org.kohsuke.github.GHTeam.Privacy;

import java.io.IOException;
import java.util.List;
import java.util.Set;

import static org.junit.Assert.assertEquals;
Expand Down Expand Up @@ -34,6 +35,31 @@ public void testSetDescription() throws IOException {
assertEquals(description, team.getDescription());
}

@Test
public void testlistMembersAdmin() throws IOException {
String teamSlug = "dummy-team";

GHTeam team = gitHub.getOrganization(GITHUB_API_TEST_ORG).getTeamBySlug(teamSlug);

List<GHUser> admins = team.listMembers("admin").asList();

assertNotNull(admins);
assertThat("One admin in dummy team", admins.size() == 1);
assertThat("Specific user in admin team",
admins.stream().anyMatch(ghUser -> ghUser.getLogin().equals("bitwiseman")));
}

@Test
public void testlistMembersNoMatch() throws IOException {
String teamSlug = "dummy-team";

GHTeam team = gitHub.getOrganization(GITHUB_API_TEST_ORG).getTeamBySlug(teamSlug);

List<GHUser> justMembers = team.listMembers("member").asList();

assertThat("No regular members in team", justMembers.isEmpty());
}

@Test
public void testSetPrivacy() throws IOException {
String teamSlug = "dummy-team";
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
{
"login": "hub4j-test-org",
"id": 7544739,
"node_id": "MDEyOk9yZ2FuaXphdGlvbjc1NDQ3Mzk=",
"url": "https://api.github.com/orgs/hub4j-test-org",
"repos_url": "https://api.github.com/orgs/hub4j-test-org/repos",
"events_url": "https://api.github.com/orgs/hub4j-test-org/events",
"hooks_url": "https://api.github.com/orgs/hub4j-test-org/hooks",
"issues_url": "https://api.github.com/orgs/hub4j-test-org/issues",
"members_url": "https://api.github.com/orgs/hub4j-test-org/members{/member}",
"public_members_url": "https://api.github.com/orgs/hub4j-test-org/public_members{/member}",
"avatar_url": "https://avatars3.githubusercontent.com/u/7544739?v=4",
"description": "Hub4j Test Org Description (this could be null or blank too)",
"name": "Hub4j Test Org Name (this could be null or blank too)",
"company": null,
"blog": "https://hub4j.url.io/could/be/null",
"location": "Hub4j Test Org Location (this could be null or blank too)",
"email": "hub4jtestorgemail@could.be.null.com",
"twitter_username": null,
"is_verified": false,
"has_organization_projects": true,
"has_repository_projects": true,
"public_repos": 13,
"public_gists": 0,
"followers": 0,
"following": 0,
"html_url": "https://github.com/hub4j-test-org",
"created_at": "2014-05-10T19:39:11Z",
"updated_at": "2020-06-04T05:56:10Z",
"type": "Organization",
"total_private_repos": 1,
"owned_private_repos": 1,
"private_gists": 0,
"disk_usage": 152,
"collaborators": 0,
"billing_email": "kk@kohsuke.org",
"default_repository_permission": "none",
"members_can_create_repositories": false,
"two_factor_requirement_enabled": false,
"members_can_create_pages": true,
"plan": {
"name": "free",
"space": 976562499,
"private_repos": 10000,
"filled_seats": 18,
"seats": 3
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
{
"name": "dummy-team",
"id": 3451996,
"node_id": "MDQ6VGVhbTM0NTE5OTY=",
"slug": "dummy-team",
"description": "Updated by API TestModified",
"privacy": "closed",
"url": "https://api.github.com/organizations/7544739/team/3451996",
"html_url": "https://github.com/orgs/hub4j-test-org/teams/dummy-team",
"members_url": "https://api.github.com/organizations/7544739/team/3451996/members{/member}",
"repositories_url": "https://api.github.com/organizations/7544739/team/3451996/repos",
"permission": "pull",
"created_at": "2019-10-03T21:46:12Z",
"updated_at": "2020-06-02T19:31:50Z",
"members_count": 1,
"repos_count": 1,
"organization": {
"login": "hub4j-test-org",
"id": 7544739,
"node_id": "MDEyOk9yZ2FuaXphdGlvbjc1NDQ3Mzk=",
"url": "https://api.github.com/orgs/hub4j-test-org",
"repos_url": "https://api.github.com/orgs/hub4j-test-org/repos",
"events_url": "https://api.github.com/orgs/hub4j-test-org/events",
"hooks_url": "https://api.github.com/orgs/hub4j-test-org/hooks",
"issues_url": "https://api.github.com/orgs/hub4j-test-org/issues",
"members_url": "https://api.github.com/orgs/hub4j-test-org/members{/member}",
"public_members_url": "https://api.github.com/orgs/hub4j-test-org/public_members{/member}",
"avatar_url": "https://avatars3.githubusercontent.com/u/7544739?v=4",
"description": "Hub4j Test Org Description (this could be null or blank too)",
"name": "Hub4j Test Org Name (this could be null or blank too)",
"company": null,
"blog": "https://hub4j.url.io/could/be/null",
"location": "Hub4j Test Org Location (this could be null or blank too)",
"email": "hub4jtestorgemail@could.be.null.com",
"twitter_username": null,
"is_verified": false,
"has_organization_projects": true,
"has_repository_projects": true,
"public_repos": 13,
"public_gists": 0,
"followers": 0,
"following": 0,
"html_url": "https://github.com/hub4j-test-org",
"created_at": "2014-05-10T19:39:11Z",
"updated_at": "2020-06-04T05:56:10Z",
"type": "Organization"
},
"parent": null
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
[
{
"login": "bitwiseman",
"id": 1958953,
"node_id": "MDQ6VXNlcjE5NTg5NTM=",
"avatar_url": "https://avatars3.githubusercontent.com/u/1958953?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/bitwiseman",
"html_url": "https://github.com/bitwiseman",
"followers_url": "https://api.github.com/users/bitwiseman/followers",
"following_url": "https://api.github.com/users/bitwiseman/following{/other_user}",
"gists_url": "https://api.github.com/users/bitwiseman/gists{/gist_id}",
"starred_url": "https://api.github.com/users/bitwiseman/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/bitwiseman/subscriptions",
"organizations_url": "https://api.github.com/users/bitwiseman/orgs",
"repos_url": "https://api.github.com/users/bitwiseman/repos",
"events_url": "https://api.github.com/users/bitwiseman/events{/privacy}",
"received_events_url": "https://api.github.com/users/bitwiseman/received_events",
"type": "User",
"site_admin": false
}
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
{
"id": "ac370d2e-d963-4c5e-aa4b-f2a0cc232163",
"name": "orgs_hub4j-test-org",
"request": {
"url": "/orgs/hub4j-test-org",
"method": "GET",
"headers": {
"Accept": {
"equalTo": "text/html, image/gif, image/jpeg, *; q=.2, */*; q=.2"
}
}
},
"response": {
"status": 200,
"bodyFileName": "orgs_hub4j-test-org-1.json",
"headers": {
"Date": "Wed, 04 Nov 2020 08:59:46 GMT",
"Content-Type": "application/json; charset=utf-8",
"Server": "GitHub.com",
"Status": "200 OK",
"Cache-Control": "private, max-age=60, s-maxage=60",
"Vary": [
"Accept, Authorization, Cookie, X-GitHub-OTP",
"Accept-Encoding, Accept, X-Requested-With",
"Accept-Encoding"
],
"ETag": "W/\"5c55d16bf1d59fa9c42072f73eac7e9484cb6b90e83ce9fecee1423b52bf612f\"",
"Last-Modified": "Thu, 04 Jun 2020 05:56:10 GMT",
"X-GitHub-Media-Type": "unknown, github.v3",
"X-RateLimit-Limit": "5000",
"X-RateLimit-Remaining": "4993",
"X-RateLimit-Reset": "1604483790",
"X-RateLimit-Used": "7",
"Strict-Transport-Security": "max-age=31536000; includeSubdomains; preload",
"X-Frame-Options": "deny",
"X-Content-Type-Options": "nosniff",
"X-XSS-Protection": "1; mode=block",
"Referrer-Policy": "origin-when-cross-origin, strict-origin-when-cross-origin",
"Content-Security-Policy": "default-src 'none'",
"X-GitHub-Request-Id": "DB4A:2593:34CDD08:3BFC6A5:5FA26D81"
}
},
"uuid": "ac370d2e-d963-4c5e-aa4b-f2a0cc232163",
"persistent": true,
"insertionIndex": 1
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
{
"id": "b7b0e265-4f0e-4b4d-a9ac-bb88067f8f96",
"name": "orgs_hub4j-test-org_teams_dummy-team",
"request": {
"url": "/orgs/hub4j-test-org/teams/dummy-team",
"method": "GET",
"headers": {
"Accept": {
"equalTo": "text/html, image/gif, image/jpeg, *; q=.2, */*; q=.2"
}
}
},
"response": {
"status": 200,
"bodyFileName": "orgs_hub4j-test-org_teams_dummy-team-2.json",
"headers": {
"Date": "Wed, 04 Nov 2020 08:59:46 GMT",
"Content-Type": "application/json; charset=utf-8",
"Server": "GitHub.com",
"Status": "200 OK",
"Cache-Control": "private, max-age=60, s-maxage=60",
"Vary": [
"Accept, Authorization, Cookie, X-GitHub-OTP",
"Accept-Encoding, Accept, X-Requested-With",
"Accept-Encoding"
],
"ETag": "W/\"087f5aba00a8363b8754fb3c15ba46d72105cdeb0c841f21bd3009a71b39aa7a\"",
"Last-Modified": "Tue, 02 Jun 2020 19:31:50 GMT",
"X-GitHub-Media-Type": "unknown, github.v3",
"X-RateLimit-Limit": "5000",
"X-RateLimit-Remaining": "4992",
"X-RateLimit-Reset": "1604483790",
"X-RateLimit-Used": "8",
"Strict-Transport-Security": "max-age=31536000; includeSubdomains; preload",
"X-Frame-Options": "deny",
"X-Content-Type-Options": "nosniff",
"X-XSS-Protection": "1; mode=block",
"Referrer-Policy": "origin-when-cross-origin, strict-origin-when-cross-origin",
"Content-Security-Policy": "default-src 'none'",
"X-GitHub-Request-Id": "DB4A:2593:34CDD66:3BFC6C8:5FA26D82"
}
},
"uuid": "b7b0e265-4f0e-4b4d-a9ac-bb88067f8f96",
"persistent": true,
"insertionIndex": 2
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
{
"id": "5ae66057-a096-48c4-a32c-b3baff1351d0",
"name": "teams_3451996_members",
"request": {
"url": "/teams/3451996/members?role=admin",
"method": "GET",
"headers": {
"Accept": {
"equalTo": "text/html, image/gif, image/jpeg, *; q=.2, */*; q=.2"
}
}
},
"response": {
"status": 200,
"bodyFileName": "teams_3451996_members-3.json",
"headers": {
"Date": "Wed, 04 Nov 2020 08:59:47 GMT",
"Content-Type": "application/json; charset=utf-8",
"Server": "GitHub.com",
"Status": "200 OK",
"Cache-Control": "private, max-age=60, s-maxage=60",
"Vary": [
"Accept, Authorization, Cookie, X-GitHub-OTP",
"Accept-Encoding, Accept, X-Requested-With",
"Accept-Encoding"
],
"ETag": "W/\"5e0877dcfff7c4b3268d7d416b181ebafe1714c592ff52d01d75930662c0c556\"",
"X-GitHub-Media-Type": "unknown, github.v3",
"Deprecation": "Sat, 01 Feb 2020 00:00:00 GMT",
"Sunset": "Mon, 01 Feb 2021 00:00:00 GMT",
"X-RateLimit-Limit": "5000",
"X-RateLimit-Remaining": "4991",
"X-RateLimit-Reset": "1604483790",
"X-RateLimit-Used": "9",
"Strict-Transport-Security": "max-age=31536000; includeSubdomains; preload",
"X-Frame-Options": "deny",
"X-Content-Type-Options": "nosniff",
"X-XSS-Protection": "1; mode=block",
"Referrer-Policy": "origin-when-cross-origin, strict-origin-when-cross-origin",
"Content-Security-Policy": "default-src 'none'",
"X-GitHub-Request-Id": "DB4A:2593:34CDD8A:3BFC734:5FA26D82",
"Link": "<https://docs.github.com/changes/2020-01-21-moving-the-team-api-endpoints/>; rel=\"deprecation\"; type=\"text/html\", <https://api.github.com/organizations/7544739/team/3451996/members>; rel=\"alternate\""
}
},
"uuid": "5ae66057-a096-48c4-a32c-b3baff1351d0",
"persistent": true,
"insertionIndex": 3
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
{
"login": "hub4j-test-org",
"id": 7544739,
"node_id": "MDEyOk9yZ2FuaXphdGlvbjc1NDQ3Mzk=",
"url": "https://api.github.com/orgs/hub4j-test-org",
"repos_url": "https://api.github.com/orgs/hub4j-test-org/repos",
"events_url": "https://api.github.com/orgs/hub4j-test-org/events",
"hooks_url": "https://api.github.com/orgs/hub4j-test-org/hooks",
"issues_url": "https://api.github.com/orgs/hub4j-test-org/issues",
"members_url": "https://api.github.com/orgs/hub4j-test-org/members{/member}",
"public_members_url": "https://api.github.com/orgs/hub4j-test-org/public_members{/member}",
"avatar_url": "https://avatars3.githubusercontent.com/u/7544739?v=4",
"description": "Hub4j Test Org Description (this could be null or blank too)",
"name": "Hub4j Test Org Name (this could be null or blank too)",
"company": null,
"blog": "https://hub4j.url.io/could/be/null",
"location": "Hub4j Test Org Location (this could be null or blank too)",
"email": "hub4jtestorgemail@could.be.null.com",
"twitter_username": null,
"is_verified": false,
"has_organization_projects": true,
"has_repository_projects": true,
"public_repos": 13,
"public_gists": 0,
"followers": 0,
"following": 0,
"html_url": "https://github.com/hub4j-test-org",
"created_at": "2014-05-10T19:39:11Z",
"updated_at": "2020-06-04T05:56:10Z",
"type": "Organization",
"total_private_repos": 1,
"owned_private_repos": 1,
"private_gists": 0,
"disk_usage": 152,
"collaborators": 0,
"billing_email": "kk@kohsuke.org",
"default_repository_permission": "none",
"members_can_create_repositories": false,
"two_factor_requirement_enabled": false,
"members_can_create_pages": true,
"plan": {
"name": "free",
"space": 976562499,
"private_repos": 10000,
"filled_seats": 18,
"seats": 3
}
}
Loading