Skip to content

Commit 5ac65aa

Browse files
authored
Merge pull request hub4j#715 from Sage-Pierce/hub4j#714
[hub4j#714]Fix query parameter construction of org member filter
2 parents 4aef92e + a1b0e77 commit 5ac65aa

14 files changed

Lines changed: 1007 additions & 5 deletions

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

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,7 @@ public PagedIterable<GHUser> listPublicMembers() throws IOException {
279279
}
280280

281281
private PagedIterable<GHUser> listMembers(String suffix) throws IOException {
282-
return listMembers(suffix, null);
282+
return listMembers(suffix, null, null);
283283
}
284284

285285
/**
@@ -292,13 +292,28 @@ private PagedIterable<GHUser> listMembers(String suffix) throws IOException {
292292
* the io exception
293293
*/
294294
public PagedIterable<GHUser> listMembersWithFilter(String filter) throws IOException {
295-
return listMembers("members", filter);
295+
return listMembers("members", filter, null);
296296
}
297297

298-
private PagedIterable<GHUser> listMembers(final String suffix, final String filter) throws IOException {
299-
String filterParams = (filter == null) ? "" : ("?filter=" + filter);
298+
/**
299+
* List members with specified role paged iterable.
300+
*
301+
* @param role
302+
* the role
303+
* @return the paged iterable
304+
* @throws IOException
305+
* the io exception
306+
*/
307+
public PagedIterable<GHUser> listMembersWithRole(String role) throws IOException {
308+
return listMembers("members", null, role);
309+
}
310+
311+
private PagedIterable<GHUser> listMembers(final String suffix, final String filter, String role)
312+
throws IOException {
300313
return root.createRequest()
301-
.withUrlPath(String.format("/orgs/%s/%s%s", login, suffix, filterParams))
314+
.withUrlPath(String.format("/orgs/%s/%s", login, suffix))
315+
.with("filter", filter)
316+
.with("role", role)
302317
.toIterable(GHUser[].class, item -> item.wrapUp(root));
303318
}
304319

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

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import org.kohsuke.github.GHOrganization.Permission;
88

99
import java.io.IOException;
10+
import java.util.List;
1011

1112
public class GHOrganizationTest extends AbstractGitHubWireMockTest {
1213

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

80+
@Test
81+
public void testListMembersWithFilter() throws IOException {
82+
GHOrganization org = gitHub.getOrganization(GITHUB_API_TEST_ORG);
83+
84+
List<GHUser> admins = org.listMembersWithFilter("all").asList();
85+
86+
assertNotNull(admins);
87+
assertTrue(admins.size() >= 12); // In case more are added in the future
88+
assertTrue(admins.stream().anyMatch(ghUser -> ghUser.getLogin().equals("alexanderrtaylor")));
89+
assertTrue(admins.stream().anyMatch(ghUser -> ghUser.getLogin().equals("asthinasthi")));
90+
assertTrue(admins.stream().anyMatch(ghUser -> ghUser.getLogin().equals("bitwiseman")));
91+
assertTrue(admins.stream().anyMatch(ghUser -> ghUser.getLogin().equals("farmdawgnation")));
92+
assertTrue(admins.stream().anyMatch(ghUser -> ghUser.getLogin().equals("halkeye")));
93+
assertTrue(admins.stream().anyMatch(ghUser -> ghUser.getLogin().equals("jberglund-BSFT")));
94+
assertTrue(admins.stream().anyMatch(ghUser -> ghUser.getLogin().equals("kohsuke")));
95+
assertTrue(admins.stream().anyMatch(ghUser -> ghUser.getLogin().equals("kohsuke2")));
96+
assertTrue(admins.stream().anyMatch(ghUser -> ghUser.getLogin().equals("martinvanzijl")));
97+
assertTrue(admins.stream().anyMatch(ghUser -> ghUser.getLogin().equals("PauloMigAlmeida")));
98+
assertTrue(admins.stream().anyMatch(ghUser -> ghUser.getLogin().equals("Sage-Pierce")));
99+
assertTrue(admins.stream().anyMatch(ghUser -> ghUser.getLogin().equals("timja")));
100+
}
101+
102+
@Test
103+
public void testListMembersWithRole() throws IOException {
104+
GHOrganization org = gitHub.getOrganization(GITHUB_API_TEST_ORG);
105+
106+
List<GHUser> admins = org.listMembersWithRole("admin").asList();
107+
108+
assertNotNull(admins);
109+
assertTrue(admins.size() >= 12); // In case more are added in the future
110+
assertTrue(admins.stream().anyMatch(ghUser -> ghUser.getLogin().equals("alexanderrtaylor")));
111+
assertTrue(admins.stream().anyMatch(ghUser -> ghUser.getLogin().equals("asthinasthi")));
112+
assertTrue(admins.stream().anyMatch(ghUser -> ghUser.getLogin().equals("bitwiseman")));
113+
assertTrue(admins.stream().anyMatch(ghUser -> ghUser.getLogin().equals("farmdawgnation")));
114+
assertTrue(admins.stream().anyMatch(ghUser -> ghUser.getLogin().equals("halkeye")));
115+
assertTrue(admins.stream().anyMatch(ghUser -> ghUser.getLogin().equals("jberglund-BSFT")));
116+
assertTrue(admins.stream().anyMatch(ghUser -> ghUser.getLogin().equals("kohsuke")));
117+
assertTrue(admins.stream().anyMatch(ghUser -> ghUser.getLogin().equals("kohsuke2")));
118+
assertTrue(admins.stream().anyMatch(ghUser -> ghUser.getLogin().equals("martinvanzijl")));
119+
assertTrue(admins.stream().anyMatch(ghUser -> ghUser.getLogin().equals("PauloMigAlmeida")));
120+
assertTrue(admins.stream().anyMatch(ghUser -> ghUser.getLogin().equals("Sage-Pierce")));
121+
assertTrue(admins.stream().anyMatch(ghUser -> ghUser.getLogin().equals("timja")));
122+
}
123+
79124
@Test
80125
public void testCreateTeamWithRepoAccess() throws IOException {
81126
String REPO_NAME = "github-api";
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
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": 11,
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+
"total_private_repos": 0,
26+
"owned_private_repos": 0,
27+
"private_gists": 0,
28+
"disk_usage": 147,
29+
"collaborators": 0,
30+
"billing_email": "kk@kohsuke.org",
31+
"default_repository_permission": "none",
32+
"members_can_create_repositories": false,
33+
"two_factor_requirement_enabled": false,
34+
"plan": {
35+
"name": "free",
36+
"space": 976562499,
37+
"private_repos": 0,
38+
"filled_seats": 12,
39+
"seats": 0
40+
}
41+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,242 @@
1+
[
2+
{
3+
"login": "alexanderrtaylor",
4+
"id": 852179,
5+
"node_id": "MDQ6VXNlcjg1MjE3OQ==",
6+
"avatar_url": "https://avatars0.githubusercontent.com/u/852179?v=4",
7+
"gravatar_id": "",
8+
"url": "https://api.github.com/users/alexanderrtaylor",
9+
"html_url": "https://github.com/alexanderrtaylor",
10+
"followers_url": "https://api.github.com/users/alexanderrtaylor/followers",
11+
"following_url": "https://api.github.com/users/alexanderrtaylor/following{/other_user}",
12+
"gists_url": "https://api.github.com/users/alexanderrtaylor/gists{/gist_id}",
13+
"starred_url": "https://api.github.com/users/alexanderrtaylor/starred{/owner}{/repo}",
14+
"subscriptions_url": "https://api.github.com/users/alexanderrtaylor/subscriptions",
15+
"organizations_url": "https://api.github.com/users/alexanderrtaylor/orgs",
16+
"repos_url": "https://api.github.com/users/alexanderrtaylor/repos",
17+
"events_url": "https://api.github.com/users/alexanderrtaylor/events{/privacy}",
18+
"received_events_url": "https://api.github.com/users/alexanderrtaylor/received_events",
19+
"type": "User",
20+
"site_admin": false
21+
},
22+
{
23+
"login": "asthinasthi",
24+
"id": 4577101,
25+
"node_id": "MDQ6VXNlcjQ1NzcxMDE=",
26+
"avatar_url": "https://avatars1.githubusercontent.com/u/4577101?v=4",
27+
"gravatar_id": "",
28+
"url": "https://api.github.com/users/asthinasthi",
29+
"html_url": "https://github.com/asthinasthi",
30+
"followers_url": "https://api.github.com/users/asthinasthi/followers",
31+
"following_url": "https://api.github.com/users/asthinasthi/following{/other_user}",
32+
"gists_url": "https://api.github.com/users/asthinasthi/gists{/gist_id}",
33+
"starred_url": "https://api.github.com/users/asthinasthi/starred{/owner}{/repo}",
34+
"subscriptions_url": "https://api.github.com/users/asthinasthi/subscriptions",
35+
"organizations_url": "https://api.github.com/users/asthinasthi/orgs",
36+
"repos_url": "https://api.github.com/users/asthinasthi/repos",
37+
"events_url": "https://api.github.com/users/asthinasthi/events{/privacy}",
38+
"received_events_url": "https://api.github.com/users/asthinasthi/received_events",
39+
"type": "User",
40+
"site_admin": false
41+
},
42+
{
43+
"login": "bitwiseman",
44+
"id": 1958953,
45+
"node_id": "MDQ6VXNlcjE5NTg5NTM=",
46+
"avatar_url": "https://avatars3.githubusercontent.com/u/1958953?v=4",
47+
"gravatar_id": "",
48+
"url": "https://api.github.com/users/bitwiseman",
49+
"html_url": "https://github.com/bitwiseman",
50+
"followers_url": "https://api.github.com/users/bitwiseman/followers",
51+
"following_url": "https://api.github.com/users/bitwiseman/following{/other_user}",
52+
"gists_url": "https://api.github.com/users/bitwiseman/gists{/gist_id}",
53+
"starred_url": "https://api.github.com/users/bitwiseman/starred{/owner}{/repo}",
54+
"subscriptions_url": "https://api.github.com/users/bitwiseman/subscriptions",
55+
"organizations_url": "https://api.github.com/users/bitwiseman/orgs",
56+
"repos_url": "https://api.github.com/users/bitwiseman/repos",
57+
"events_url": "https://api.github.com/users/bitwiseman/events{/privacy}",
58+
"received_events_url": "https://api.github.com/users/bitwiseman/received_events",
59+
"type": "User",
60+
"site_admin": false
61+
},
62+
{
63+
"login": "farmdawgnation",
64+
"id": 620189,
65+
"node_id": "MDQ6VXNlcjYyMDE4OQ==",
66+
"avatar_url": "https://avatars2.githubusercontent.com/u/620189?v=4",
67+
"gravatar_id": "",
68+
"url": "https://api.github.com/users/farmdawgnation",
69+
"html_url": "https://github.com/farmdawgnation",
70+
"followers_url": "https://api.github.com/users/farmdawgnation/followers",
71+
"following_url": "https://api.github.com/users/farmdawgnation/following{/other_user}",
72+
"gists_url": "https://api.github.com/users/farmdawgnation/gists{/gist_id}",
73+
"starred_url": "https://api.github.com/users/farmdawgnation/starred{/owner}{/repo}",
74+
"subscriptions_url": "https://api.github.com/users/farmdawgnation/subscriptions",
75+
"organizations_url": "https://api.github.com/users/farmdawgnation/orgs",
76+
"repos_url": "https://api.github.com/users/farmdawgnation/repos",
77+
"events_url": "https://api.github.com/users/farmdawgnation/events{/privacy}",
78+
"received_events_url": "https://api.github.com/users/farmdawgnation/received_events",
79+
"type": "User",
80+
"site_admin": false
81+
},
82+
{
83+
"login": "halkeye",
84+
"id": 110087,
85+
"node_id": "MDQ6VXNlcjExMDA4Nw==",
86+
"avatar_url": "https://avatars3.githubusercontent.com/u/110087?v=4",
87+
"gravatar_id": "",
88+
"url": "https://api.github.com/users/halkeye",
89+
"html_url": "https://github.com/halkeye",
90+
"followers_url": "https://api.github.com/users/halkeye/followers",
91+
"following_url": "https://api.github.com/users/halkeye/following{/other_user}",
92+
"gists_url": "https://api.github.com/users/halkeye/gists{/gist_id}",
93+
"starred_url": "https://api.github.com/users/halkeye/starred{/owner}{/repo}",
94+
"subscriptions_url": "https://api.github.com/users/halkeye/subscriptions",
95+
"organizations_url": "https://api.github.com/users/halkeye/orgs",
96+
"repos_url": "https://api.github.com/users/halkeye/repos",
97+
"events_url": "https://api.github.com/users/halkeye/events{/privacy}",
98+
"received_events_url": "https://api.github.com/users/halkeye/received_events",
99+
"type": "User",
100+
"site_admin": false
101+
},
102+
{
103+
"login": "jberglund-BSFT",
104+
"id": 19560713,
105+
"node_id": "MDQ6VXNlcjE5NTYwNzEz",
106+
"avatar_url": "https://avatars3.githubusercontent.com/u/19560713?v=4",
107+
"gravatar_id": "",
108+
"url": "https://api.github.com/users/jberglund-BSFT",
109+
"html_url": "https://github.com/jberglund-BSFT",
110+
"followers_url": "https://api.github.com/users/jberglund-BSFT/followers",
111+
"following_url": "https://api.github.com/users/jberglund-BSFT/following{/other_user}",
112+
"gists_url": "https://api.github.com/users/jberglund-BSFT/gists{/gist_id}",
113+
"starred_url": "https://api.github.com/users/jberglund-BSFT/starred{/owner}{/repo}",
114+
"subscriptions_url": "https://api.github.com/users/jberglund-BSFT/subscriptions",
115+
"organizations_url": "https://api.github.com/users/jberglund-BSFT/orgs",
116+
"repos_url": "https://api.github.com/users/jberglund-BSFT/repos",
117+
"events_url": "https://api.github.com/users/jberglund-BSFT/events{/privacy}",
118+
"received_events_url": "https://api.github.com/users/jberglund-BSFT/received_events",
119+
"type": "User",
120+
"site_admin": false
121+
},
122+
{
123+
"login": "kohsuke",
124+
"id": 50003,
125+
"node_id": "MDQ6VXNlcjUwMDAz",
126+
"avatar_url": "https://avatars1.githubusercontent.com/u/50003?v=4",
127+
"gravatar_id": "",
128+
"url": "https://api.github.com/users/kohsuke",
129+
"html_url": "https://github.com/kohsuke",
130+
"followers_url": "https://api.github.com/users/kohsuke/followers",
131+
"following_url": "https://api.github.com/users/kohsuke/following{/other_user}",
132+
"gists_url": "https://api.github.com/users/kohsuke/gists{/gist_id}",
133+
"starred_url": "https://api.github.com/users/kohsuke/starred{/owner}{/repo}",
134+
"subscriptions_url": "https://api.github.com/users/kohsuke/subscriptions",
135+
"organizations_url": "https://api.github.com/users/kohsuke/orgs",
136+
"repos_url": "https://api.github.com/users/kohsuke/repos",
137+
"events_url": "https://api.github.com/users/kohsuke/events{/privacy}",
138+
"received_events_url": "https://api.github.com/users/kohsuke/received_events",
139+
"type": "User",
140+
"site_admin": false
141+
},
142+
{
143+
"login": "kohsuke2",
144+
"id": 1329242,
145+
"node_id": "MDQ6VXNlcjEzMjkyNDI=",
146+
"avatar_url": "https://avatars2.githubusercontent.com/u/1329242?v=4",
147+
"gravatar_id": "",
148+
"url": "https://api.github.com/users/kohsuke2",
149+
"html_url": "https://github.com/kohsuke2",
150+
"followers_url": "https://api.github.com/users/kohsuke2/followers",
151+
"following_url": "https://api.github.com/users/kohsuke2/following{/other_user}",
152+
"gists_url": "https://api.github.com/users/kohsuke2/gists{/gist_id}",
153+
"starred_url": "https://api.github.com/users/kohsuke2/starred{/owner}{/repo}",
154+
"subscriptions_url": "https://api.github.com/users/kohsuke2/subscriptions",
155+
"organizations_url": "https://api.github.com/users/kohsuke2/orgs",
156+
"repos_url": "https://api.github.com/users/kohsuke2/repos",
157+
"events_url": "https://api.github.com/users/kohsuke2/events{/privacy}",
158+
"received_events_url": "https://api.github.com/users/kohsuke2/received_events",
159+
"type": "User",
160+
"site_admin": false
161+
},
162+
{
163+
"login": "martinvanzijl",
164+
"id": 24422213,
165+
"node_id": "MDQ6VXNlcjI0NDIyMjEz",
166+
"avatar_url": "https://avatars0.githubusercontent.com/u/24422213?v=4",
167+
"gravatar_id": "",
168+
"url": "https://api.github.com/users/martinvanzijl",
169+
"html_url": "https://github.com/martinvanzijl",
170+
"followers_url": "https://api.github.com/users/martinvanzijl/followers",
171+
"following_url": "https://api.github.com/users/martinvanzijl/following{/other_user}",
172+
"gists_url": "https://api.github.com/users/martinvanzijl/gists{/gist_id}",
173+
"starred_url": "https://api.github.com/users/martinvanzijl/starred{/owner}{/repo}",
174+
"subscriptions_url": "https://api.github.com/users/martinvanzijl/subscriptions",
175+
"organizations_url": "https://api.github.com/users/martinvanzijl/orgs",
176+
"repos_url": "https://api.github.com/users/martinvanzijl/repos",
177+
"events_url": "https://api.github.com/users/martinvanzijl/events{/privacy}",
178+
"received_events_url": "https://api.github.com/users/martinvanzijl/received_events",
179+
"type": "User",
180+
"site_admin": false
181+
},
182+
{
183+
"login": "PauloMigAlmeida",
184+
"id": 1011868,
185+
"node_id": "MDQ6VXNlcjEwMTE4Njg=",
186+
"avatar_url": "https://avatars1.githubusercontent.com/u/1011868?v=4",
187+
"gravatar_id": "",
188+
"url": "https://api.github.com/users/PauloMigAlmeida",
189+
"html_url": "https://github.com/PauloMigAlmeida",
190+
"followers_url": "https://api.github.com/users/PauloMigAlmeida/followers",
191+
"following_url": "https://api.github.com/users/PauloMigAlmeida/following{/other_user}",
192+
"gists_url": "https://api.github.com/users/PauloMigAlmeida/gists{/gist_id}",
193+
"starred_url": "https://api.github.com/users/PauloMigAlmeida/starred{/owner}{/repo}",
194+
"subscriptions_url": "https://api.github.com/users/PauloMigAlmeida/subscriptions",
195+
"organizations_url": "https://api.github.com/users/PauloMigAlmeida/orgs",
196+
"repos_url": "https://api.github.com/users/PauloMigAlmeida/repos",
197+
"events_url": "https://api.github.com/users/PauloMigAlmeida/events{/privacy}",
198+
"received_events_url": "https://api.github.com/users/PauloMigAlmeida/received_events",
199+
"type": "User",
200+
"site_admin": false
201+
},
202+
{
203+
"login": "Sage-Pierce",
204+
"id": 5396306,
205+
"node_id": "MDQ6VXNlcjUzOTYzMDY=",
206+
"avatar_url": "https://avatars3.githubusercontent.com/u/5396306?v=4",
207+
"gravatar_id": "",
208+
"url": "https://api.github.com/users/Sage-Pierce",
209+
"html_url": "https://github.com/Sage-Pierce",
210+
"followers_url": "https://api.github.com/users/Sage-Pierce/followers",
211+
"following_url": "https://api.github.com/users/Sage-Pierce/following{/other_user}",
212+
"gists_url": "https://api.github.com/users/Sage-Pierce/gists{/gist_id}",
213+
"starred_url": "https://api.github.com/users/Sage-Pierce/starred{/owner}{/repo}",
214+
"subscriptions_url": "https://api.github.com/users/Sage-Pierce/subscriptions",
215+
"organizations_url": "https://api.github.com/users/Sage-Pierce/orgs",
216+
"repos_url": "https://api.github.com/users/Sage-Pierce/repos",
217+
"events_url": "https://api.github.com/users/Sage-Pierce/events{/privacy}",
218+
"received_events_url": "https://api.github.com/users/Sage-Pierce/received_events",
219+
"type": "User",
220+
"site_admin": false
221+
},
222+
{
223+
"login": "timja",
224+
"id": 21194782,
225+
"node_id": "MDQ6VXNlcjIxMTk0Nzgy",
226+
"avatar_url": "https://avatars3.githubusercontent.com/u/21194782?v=4",
227+
"gravatar_id": "",
228+
"url": "https://api.github.com/users/timja",
229+
"html_url": "https://github.com/timja",
230+
"followers_url": "https://api.github.com/users/timja/followers",
231+
"following_url": "https://api.github.com/users/timja/following{/other_user}",
232+
"gists_url": "https://api.github.com/users/timja/gists{/gist_id}",
233+
"starred_url": "https://api.github.com/users/timja/starred{/owner}{/repo}",
234+
"subscriptions_url": "https://api.github.com/users/timja/subscriptions",
235+
"organizations_url": "https://api.github.com/users/timja/orgs",
236+
"repos_url": "https://api.github.com/users/timja/repos",
237+
"events_url": "https://api.github.com/users/timja/events{/privacy}",
238+
"received_events_url": "https://api.github.com/users/timja/received_events",
239+
"type": "User",
240+
"site_admin": false
241+
}
242+
]

0 commit comments

Comments
 (0)