Skip to content
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
25 changes: 20 additions & 5 deletions src/main/java/org/kohsuke/github/GHOrganization.java
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ public PagedIterable<GHUser> listPublicMembers() throws IOException {
}

private PagedIterable<GHUser> listMembers(String suffix) throws IOException {
return listMembers(suffix, null);
return listMembers(suffix, null, null);
}

/**
Expand All @@ -292,13 +292,28 @@ private PagedIterable<GHUser> listMembers(String suffix) throws IOException {
* the io exception
*/
public PagedIterable<GHUser> listMembersWithFilter(String filter) throws IOException {
return listMembers("members", filter);
return listMembers("members", filter, null);
}

private PagedIterable<GHUser> listMembers(final String suffix, final String filter) throws IOException {
String filterParams = (filter == null) ? "" : ("?filter=" + filter);
/**
* List members with specified role paged iterable.
*
* @param role
* the role
* @return the paged iterable
* @throws IOException
* the io exception
*/
public PagedIterable<GHUser> listMembersWithRole(String role) throws IOException {
return listMembers("members", null, role);
}

private PagedIterable<GHUser> listMembers(final String suffix, final String filter, String role)
throws IOException {
return root.createRequest()
.withUrlPath(String.format("/orgs/%s/%s%s", login, suffix, filterParams))
.withUrlPath(String.format("/orgs/%s/%s", login, suffix))
.with("filter", filter)
.with("role", role)
.toIterable(GHUser[].class, item -> item.wrapUp(root));
}

Expand Down
45 changes: 45 additions & 0 deletions src/test/java/org/kohsuke/github/GHOrganizationTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import org.kohsuke.github.GHOrganization.Permission;

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

public class GHOrganizationTest extends AbstractGitHubWireMockTest {

Expand Down Expand Up @@ -76,6 +77,50 @@ public void testInviteUser() throws IOException {
// assertTrue(org.hasMember(user));
}

@Test
public void testListMembersWithFilter() throws IOException {
GHOrganization org = gitHub.getOrganization(GITHUB_API_TEST_ORG);

List<GHUser> admins = org.listMembersWithFilter("all").asList();

assertNotNull(admins);
assertTrue(admins.size() >= 12); // In case more are added in the future
assertTrue(admins.stream().anyMatch(ghUser -> ghUser.getLogin().equals("alexanderrtaylor")));
assertTrue(admins.stream().anyMatch(ghUser -> ghUser.getLogin().equals("asthinasthi")));
assertTrue(admins.stream().anyMatch(ghUser -> ghUser.getLogin().equals("bitwiseman")));
assertTrue(admins.stream().anyMatch(ghUser -> ghUser.getLogin().equals("farmdawgnation")));
assertTrue(admins.stream().anyMatch(ghUser -> ghUser.getLogin().equals("halkeye")));
assertTrue(admins.stream().anyMatch(ghUser -> ghUser.getLogin().equals("jberglund-BSFT")));
assertTrue(admins.stream().anyMatch(ghUser -> ghUser.getLogin().equals("kohsuke")));
assertTrue(admins.stream().anyMatch(ghUser -> ghUser.getLogin().equals("kohsuke2")));
assertTrue(admins.stream().anyMatch(ghUser -> ghUser.getLogin().equals("martinvanzijl")));
assertTrue(admins.stream().anyMatch(ghUser -> ghUser.getLogin().equals("PauloMigAlmeida")));
assertTrue(admins.stream().anyMatch(ghUser -> ghUser.getLogin().equals("Sage-Pierce")));
assertTrue(admins.stream().anyMatch(ghUser -> ghUser.getLogin().equals("timja")));
}

@Test
public void testListMembersWithRole() throws IOException {
GHOrganization org = gitHub.getOrganization(GITHUB_API_TEST_ORG);

List<GHUser> admins = org.listMembersWithRole("admin").asList();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The bug was for listMembersWithFilter. Can you add a test for that as well?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done!


assertNotNull(admins);
assertTrue(admins.size() >= 12); // In case more are added in the future
assertTrue(admins.stream().anyMatch(ghUser -> ghUser.getLogin().equals("alexanderrtaylor")));
assertTrue(admins.stream().anyMatch(ghUser -> ghUser.getLogin().equals("asthinasthi")));
assertTrue(admins.stream().anyMatch(ghUser -> ghUser.getLogin().equals("bitwiseman")));
assertTrue(admins.stream().anyMatch(ghUser -> ghUser.getLogin().equals("farmdawgnation")));
assertTrue(admins.stream().anyMatch(ghUser -> ghUser.getLogin().equals("halkeye")));
assertTrue(admins.stream().anyMatch(ghUser -> ghUser.getLogin().equals("jberglund-BSFT")));
assertTrue(admins.stream().anyMatch(ghUser -> ghUser.getLogin().equals("kohsuke")));
assertTrue(admins.stream().anyMatch(ghUser -> ghUser.getLogin().equals("kohsuke2")));
assertTrue(admins.stream().anyMatch(ghUser -> ghUser.getLogin().equals("martinvanzijl")));
assertTrue(admins.stream().anyMatch(ghUser -> ghUser.getLogin().equals("PauloMigAlmeida")));
assertTrue(admins.stream().anyMatch(ghUser -> ghUser.getLogin().equals("Sage-Pierce")));
assertTrue(admins.stream().anyMatch(ghUser -> ghUser.getLogin().equals("timja")));
}

@Test
public void testCreateTeamWithRepoAccess() throws IOException {
String REPO_NAME = "github-api";
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
{
"login": "github-api-test-org",
"id": 7544739,
"node_id": "MDEyOk9yZ2FuaXphdGlvbjc1NDQ3Mzk=",
"url": "https://api.github.com/orgs/github-api-test-org",
"repos_url": "https://api.github.com/orgs/github-api-test-org/repos",
"events_url": "https://api.github.com/orgs/github-api-test-org/events",
"hooks_url": "https://api.github.com/orgs/github-api-test-org/hooks",
"issues_url": "https://api.github.com/orgs/github-api-test-org/issues",
"members_url": "https://api.github.com/orgs/github-api-test-org/members{/member}",
"public_members_url": "https://api.github.com/orgs/github-api-test-org/public_members{/member}",
"avatar_url": "https://avatars3.githubusercontent.com/u/7544739?v=4",
"description": null,
"is_verified": false,
"has_organization_projects": true,
"has_repository_projects": true,
"public_repos": 11,
"public_gists": 0,
"followers": 0,
"following": 0,
"html_url": "https://github.com/github-api-test-org",
"created_at": "2014-05-10T19:39:11Z",
"updated_at": "2015-04-20T00:42:30Z",
"type": "Organization",
"total_private_repos": 0,
"owned_private_repos": 0,
"private_gists": 0,
"disk_usage": 147,
"collaborators": 0,
"billing_email": "kk@kohsuke.org",
"default_repository_permission": "none",
"members_can_create_repositories": false,
"two_factor_requirement_enabled": false,
"plan": {
"name": "free",
"space": 976562499,
"private_repos": 0,
"filled_seats": 12,
"seats": 0
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,242 @@
[
{
"login": "alexanderrtaylor",
"id": 852179,
"node_id": "MDQ6VXNlcjg1MjE3OQ==",
"avatar_url": "https://avatars0.githubusercontent.com/u/852179?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/alexanderrtaylor",
"html_url": "https://github.com/alexanderrtaylor",
"followers_url": "https://api.github.com/users/alexanderrtaylor/followers",
"following_url": "https://api.github.com/users/alexanderrtaylor/following{/other_user}",
"gists_url": "https://api.github.com/users/alexanderrtaylor/gists{/gist_id}",
"starred_url": "https://api.github.com/users/alexanderrtaylor/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/alexanderrtaylor/subscriptions",
"organizations_url": "https://api.github.com/users/alexanderrtaylor/orgs",
"repos_url": "https://api.github.com/users/alexanderrtaylor/repos",
"events_url": "https://api.github.com/users/alexanderrtaylor/events{/privacy}",
"received_events_url": "https://api.github.com/users/alexanderrtaylor/received_events",
"type": "User",
"site_admin": false
},
{
"login": "asthinasthi",
"id": 4577101,
"node_id": "MDQ6VXNlcjQ1NzcxMDE=",
"avatar_url": "https://avatars1.githubusercontent.com/u/4577101?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/asthinasthi",
"html_url": "https://github.com/asthinasthi",
"followers_url": "https://api.github.com/users/asthinasthi/followers",
"following_url": "https://api.github.com/users/asthinasthi/following{/other_user}",
"gists_url": "https://api.github.com/users/asthinasthi/gists{/gist_id}",
"starred_url": "https://api.github.com/users/asthinasthi/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/asthinasthi/subscriptions",
"organizations_url": "https://api.github.com/users/asthinasthi/orgs",
"repos_url": "https://api.github.com/users/asthinasthi/repos",
"events_url": "https://api.github.com/users/asthinasthi/events{/privacy}",
"received_events_url": "https://api.github.com/users/asthinasthi/received_events",
"type": "User",
"site_admin": false
},
{
"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
},
{
"login": "farmdawgnation",
"id": 620189,
"node_id": "MDQ6VXNlcjYyMDE4OQ==",
"avatar_url": "https://avatars2.githubusercontent.com/u/620189?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/farmdawgnation",
"html_url": "https://github.com/farmdawgnation",
"followers_url": "https://api.github.com/users/farmdawgnation/followers",
"following_url": "https://api.github.com/users/farmdawgnation/following{/other_user}",
"gists_url": "https://api.github.com/users/farmdawgnation/gists{/gist_id}",
"starred_url": "https://api.github.com/users/farmdawgnation/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/farmdawgnation/subscriptions",
"organizations_url": "https://api.github.com/users/farmdawgnation/orgs",
"repos_url": "https://api.github.com/users/farmdawgnation/repos",
"events_url": "https://api.github.com/users/farmdawgnation/events{/privacy}",
"received_events_url": "https://api.github.com/users/farmdawgnation/received_events",
"type": "User",
"site_admin": false
},
{
"login": "halkeye",
"id": 110087,
"node_id": "MDQ6VXNlcjExMDA4Nw==",
"avatar_url": "https://avatars3.githubusercontent.com/u/110087?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/halkeye",
"html_url": "https://github.com/halkeye",
"followers_url": "https://api.github.com/users/halkeye/followers",
"following_url": "https://api.github.com/users/halkeye/following{/other_user}",
"gists_url": "https://api.github.com/users/halkeye/gists{/gist_id}",
"starred_url": "https://api.github.com/users/halkeye/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/halkeye/subscriptions",
"organizations_url": "https://api.github.com/users/halkeye/orgs",
"repos_url": "https://api.github.com/users/halkeye/repos",
"events_url": "https://api.github.com/users/halkeye/events{/privacy}",
"received_events_url": "https://api.github.com/users/halkeye/received_events",
"type": "User",
"site_admin": false
},
{
"login": "jberglund-BSFT",
"id": 19560713,
"node_id": "MDQ6VXNlcjE5NTYwNzEz",
"avatar_url": "https://avatars3.githubusercontent.com/u/19560713?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/jberglund-BSFT",
"html_url": "https://github.com/jberglund-BSFT",
"followers_url": "https://api.github.com/users/jberglund-BSFT/followers",
"following_url": "https://api.github.com/users/jberglund-BSFT/following{/other_user}",
"gists_url": "https://api.github.com/users/jberglund-BSFT/gists{/gist_id}",
"starred_url": "https://api.github.com/users/jberglund-BSFT/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/jberglund-BSFT/subscriptions",
"organizations_url": "https://api.github.com/users/jberglund-BSFT/orgs",
"repos_url": "https://api.github.com/users/jberglund-BSFT/repos",
"events_url": "https://api.github.com/users/jberglund-BSFT/events{/privacy}",
"received_events_url": "https://api.github.com/users/jberglund-BSFT/received_events",
"type": "User",
"site_admin": false
},
{
"login": "kohsuke",
"id": 50003,
"node_id": "MDQ6VXNlcjUwMDAz",
"avatar_url": "https://avatars1.githubusercontent.com/u/50003?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/kohsuke",
"html_url": "https://github.com/kohsuke",
"followers_url": "https://api.github.com/users/kohsuke/followers",
"following_url": "https://api.github.com/users/kohsuke/following{/other_user}",
"gists_url": "https://api.github.com/users/kohsuke/gists{/gist_id}",
"starred_url": "https://api.github.com/users/kohsuke/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/kohsuke/subscriptions",
"organizations_url": "https://api.github.com/users/kohsuke/orgs",
"repos_url": "https://api.github.com/users/kohsuke/repos",
"events_url": "https://api.github.com/users/kohsuke/events{/privacy}",
"received_events_url": "https://api.github.com/users/kohsuke/received_events",
"type": "User",
"site_admin": false
},
{
"login": "kohsuke2",
"id": 1329242,
"node_id": "MDQ6VXNlcjEzMjkyNDI=",
"avatar_url": "https://avatars2.githubusercontent.com/u/1329242?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/kohsuke2",
"html_url": "https://github.com/kohsuke2",
"followers_url": "https://api.github.com/users/kohsuke2/followers",
"following_url": "https://api.github.com/users/kohsuke2/following{/other_user}",
"gists_url": "https://api.github.com/users/kohsuke2/gists{/gist_id}",
"starred_url": "https://api.github.com/users/kohsuke2/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/kohsuke2/subscriptions",
"organizations_url": "https://api.github.com/users/kohsuke2/orgs",
"repos_url": "https://api.github.com/users/kohsuke2/repos",
"events_url": "https://api.github.com/users/kohsuke2/events{/privacy}",
"received_events_url": "https://api.github.com/users/kohsuke2/received_events",
"type": "User",
"site_admin": false
},
{
"login": "martinvanzijl",
"id": 24422213,
"node_id": "MDQ6VXNlcjI0NDIyMjEz",
"avatar_url": "https://avatars0.githubusercontent.com/u/24422213?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/martinvanzijl",
"html_url": "https://github.com/martinvanzijl",
"followers_url": "https://api.github.com/users/martinvanzijl/followers",
"following_url": "https://api.github.com/users/martinvanzijl/following{/other_user}",
"gists_url": "https://api.github.com/users/martinvanzijl/gists{/gist_id}",
"starred_url": "https://api.github.com/users/martinvanzijl/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/martinvanzijl/subscriptions",
"organizations_url": "https://api.github.com/users/martinvanzijl/orgs",
"repos_url": "https://api.github.com/users/martinvanzijl/repos",
"events_url": "https://api.github.com/users/martinvanzijl/events{/privacy}",
"received_events_url": "https://api.github.com/users/martinvanzijl/received_events",
"type": "User",
"site_admin": false
},
{
"login": "PauloMigAlmeida",
"id": 1011868,
"node_id": "MDQ6VXNlcjEwMTE4Njg=",
"avatar_url": "https://avatars1.githubusercontent.com/u/1011868?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/PauloMigAlmeida",
"html_url": "https://github.com/PauloMigAlmeida",
"followers_url": "https://api.github.com/users/PauloMigAlmeida/followers",
"following_url": "https://api.github.com/users/PauloMigAlmeida/following{/other_user}",
"gists_url": "https://api.github.com/users/PauloMigAlmeida/gists{/gist_id}",
"starred_url": "https://api.github.com/users/PauloMigAlmeida/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/PauloMigAlmeida/subscriptions",
"organizations_url": "https://api.github.com/users/PauloMigAlmeida/orgs",
"repos_url": "https://api.github.com/users/PauloMigAlmeida/repos",
"events_url": "https://api.github.com/users/PauloMigAlmeida/events{/privacy}",
"received_events_url": "https://api.github.com/users/PauloMigAlmeida/received_events",
"type": "User",
"site_admin": false
},
{
"login": "Sage-Pierce",
"id": 5396306,
"node_id": "MDQ6VXNlcjUzOTYzMDY=",
"avatar_url": "https://avatars3.githubusercontent.com/u/5396306?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/Sage-Pierce",
"html_url": "https://github.com/Sage-Pierce",
"followers_url": "https://api.github.com/users/Sage-Pierce/followers",
"following_url": "https://api.github.com/users/Sage-Pierce/following{/other_user}",
"gists_url": "https://api.github.com/users/Sage-Pierce/gists{/gist_id}",
"starred_url": "https://api.github.com/users/Sage-Pierce/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/Sage-Pierce/subscriptions",
"organizations_url": "https://api.github.com/users/Sage-Pierce/orgs",
"repos_url": "https://api.github.com/users/Sage-Pierce/repos",
"events_url": "https://api.github.com/users/Sage-Pierce/events{/privacy}",
"received_events_url": "https://api.github.com/users/Sage-Pierce/received_events",
"type": "User",
"site_admin": false
},
{
"login": "timja",
"id": 21194782,
"node_id": "MDQ6VXNlcjIxMTk0Nzgy",
"avatar_url": "https://avatars3.githubusercontent.com/u/21194782?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/timja",
"html_url": "https://github.com/timja",
"followers_url": "https://api.github.com/users/timja/followers",
"following_url": "https://api.github.com/users/timja/following{/other_user}",
"gists_url": "https://api.github.com/users/timja/gists{/gist_id}",
"starred_url": "https://api.github.com/users/timja/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/timja/subscriptions",
"organizations_url": "https://api.github.com/users/timja/orgs",
"repos_url": "https://api.github.com/users/timja/repos",
"events_url": "https://api.github.com/users/timja/events{/privacy}",
"received_events_url": "https://api.github.com/users/timja/received_events",
"type": "User",
"site_admin": false
}
]
Loading