Skip to content

Commit 08bde72

Browse files
authored
Merge pull request #849 from alexanderkjall/add-support-for-child-teams
Added support for fetching what teams are part of this team.
2 parents 0c22815 + 108a136 commit 08bde72

File tree

17 files changed

+725
-0
lines changed

17 files changed

+725
-0
lines changed

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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,19 @@ public PagedIterable<GHUser> listMembers() throws IOException {
174174
return root.createRequest().withUrlPath(api("/members")).toIterable(GHUser[].class, item -> item.wrapUp(root));
175175
}
176176

177+
/**
178+
* Retrieves the teams that are children of this team.
179+
*
180+
* @return the paged iterable
181+
* @throws IOException
182+
* the io exception
183+
*/
184+
public PagedIterable<GHTeam> listChildTeams() throws IOException {
185+
return root.createRequest()
186+
.withUrlPath(api("/teams"))
187+
.toIterable(GHTeam[].class, item -> item.wrapUp(this.organization));
188+
}
189+
177190
/**
178191
* Gets members.
179192
*

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

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import org.kohsuke.github.GHTeam.Privacy;
55

66
import java.io.IOException;
7+
import java.util.Set;
78

89
import static org.junit.Assert.assertEquals;
910

@@ -56,4 +57,27 @@ public void testSetPrivacy() throws IOException {
5657
assertEquals(privacy, team.getPrivacy());
5758
}
5859

60+
@Test
61+
public void testFetchChildTeams() throws IOException {
62+
String teamSlug = "dummy-team";
63+
64+
GHOrganization org = gitHub.getOrganization(GITHUB_API_TEST_ORG);
65+
GHTeam team = org.getTeamBySlug(teamSlug);
66+
Set<GHTeam> result = team.listChildTeams().toSet();
67+
68+
assertEquals(1, result.size());
69+
assertEquals("child-team-for-dummy", result.toArray(new GHTeam[]{})[0].getName());
70+
}
71+
72+
@Test
73+
public void testFetchEmptyChildTeams() throws IOException {
74+
String teamSlug = "simple-team";
75+
76+
GHOrganization org = gitHub.getOrganization(GITHUB_API_TEST_ORG);
77+
GHTeam team = org.getTeamBySlug(teamSlug);
78+
Set<GHTeam> result = team.listChildTeams().toSet();
79+
80+
assertEquals(0, result.size());
81+
}
82+
5983
}
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
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://avatars3.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": "[email protected]",
19+
"twitter_username": null,
20+
"is_verified": false,
21+
"has_organization_projects": true,
22+
"has_repository_projects": true,
23+
"public_repos": 12,
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": 0,
32+
"owned_private_repos": 0,
33+
"private_gists": null,
34+
"disk_usage": null,
35+
"collaborators": null,
36+
"billing_email": null,
37+
"default_repository_permission": null,
38+
"members_can_create_repositories": false,
39+
"two_factor_requirement_enabled": null,
40+
"plan": {
41+
"name": "free",
42+
"space": 976562499,
43+
"private_repos": 10000,
44+
"filled_seats": 19,
45+
"seats": 3
46+
}
47+
}
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": "2020-06-02T19:31:50Z",
15+
"members_count": 2,
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://avatars3.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": "[email protected]",
35+
"twitter_username": null,
36+
"is_verified": false,
37+
"has_organization_projects": true,
38+
"has_repository_projects": true,
39+
"public_repos": 12,
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+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
[
2+
{
3+
"name": "child-team-for-dummy",
4+
"id": 3903497,
5+
"node_id": "MDQ6VGVhbTM5MDM0OTc=",
6+
"slug": "child-team-for-dummy",
7+
"description": "to test the fetching of child teams",
8+
"privacy": "closed",
9+
"url": "https://api.github.com/organizations/7544739/team/3903497",
10+
"html_url": "https://github.com/orgs/hub4j-test-org/teams/child-team-for-dummy",
11+
"members_url": "https://api.github.com/organizations/7544739/team/3903497/members{/member}",
12+
"repositories_url": "https://api.github.com/organizations/7544739/team/3903497/repos",
13+
"permission": "pull",
14+
"parent": {
15+
"name": "dummy-team",
16+
"id": 3451996,
17+
"node_id": "MDQ6VGVhbTM0NTE5OTY=",
18+
"slug": "dummy-team",
19+
"description": "Updated by API TestModified",
20+
"privacy": "closed",
21+
"url": "https://api.github.com/organizations/7544739/team/3451996",
22+
"html_url": "https://github.com/orgs/hub4j-test-org/teams/dummy-team",
23+
"members_url": "https://api.github.com/organizations/7544739/team/3451996/members{/member}",
24+
"repositories_url": "https://api.github.com/organizations/7544739/team/3451996/repos",
25+
"permission": "pull"
26+
}
27+
}
28+
]
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
{
2+
"login": "alexanderkjall",
3+
"id": 647710,
4+
"node_id": "MDQ6VXNlcjY0NzcxMA==",
5+
"avatar_url": "https://avatars2.githubusercontent.com/u/647710?v=4",
6+
"gravatar_id": "",
7+
"url": "https://api.github.com/users/alexanderkjall",
8+
"html_url": "https://github.com/alexanderkjall",
9+
"followers_url": "https://api.github.com/users/alexanderkjall/followers",
10+
"following_url": "https://api.github.com/users/alexanderkjall/following{/other_user}",
11+
"gists_url": "https://api.github.com/users/alexanderkjall/gists{/gist_id}",
12+
"starred_url": "https://api.github.com/users/alexanderkjall/starred{/owner}{/repo}",
13+
"subscriptions_url": "https://api.github.com/users/alexanderkjall/subscriptions",
14+
"organizations_url": "https://api.github.com/users/alexanderkjall/orgs",
15+
"repos_url": "https://api.github.com/users/alexanderkjall/repos",
16+
"events_url": "https://api.github.com/users/alexanderkjall/events{/privacy}",
17+
"received_events_url": "https://api.github.com/users/alexanderkjall/received_events",
18+
"type": "User",
19+
"site_admin": false,
20+
"name": "Alexander Kjäll",
21+
"company": "DI",
22+
"blog": "",
23+
"location": "Oslo",
24+
"email": "[email protected]",
25+
"hireable": null,
26+
"bio": null,
27+
"twitter_username": null,
28+
"public_repos": 56,
29+
"public_gists": 6,
30+
"followers": 10,
31+
"following": 7,
32+
"created_at": "2011-03-02T20:31:15Z",
33+
"updated_at": "2020-06-19T06:10:45Z",
34+
"private_gists": 1,
35+
"total_private_repos": 1,
36+
"owned_private_repos": 1,
37+
"disk_usage": 46941,
38+
"collaborators": 0,
39+
"two_factor_authentication": true,
40+
"plan": {
41+
"name": "free",
42+
"space": 976562499,
43+
"collaborators": 0,
44+
"private_repos": 10000
45+
}
46+
}
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
{
2+
"id": "4d3be7ef-fe05-4739-9138-d2050a55a479",
3+
"name": "orgs_hub4j-test-org",
4+
"request": {
5+
"url": "/orgs/hub4j-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_hub4j-test-org-2.json",
16+
"headers": {
17+
"Date": "Fri, 19 Jun 2020 06:25:15 GMT",
18+
"Content-Type": "application/json; charset=utf-8",
19+
"Server": "GitHub.com",
20+
"Status": "200 OK",
21+
"X-RateLimit-Limit": "5000",
22+
"X-RateLimit-Remaining": "4983",
23+
"X-RateLimit-Reset": "1592551194",
24+
"Cache-Control": "private, max-age=60, s-maxage=60",
25+
"Vary": [
26+
"Accept, Authorization, Cookie, X-GitHub-OTP",
27+
"Accept-Encoding, Accept, X-Requested-With",
28+
"Accept-Encoding"
29+
],
30+
"ETag": "W/\"1cf57cb32512ca7f96e2d9133ecbb8e4\"",
31+
"Last-Modified": "Thu, 04 Jun 2020 05:56:10 GMT",
32+
"X-OAuth-Scopes": "read:discussion, read:enterprise, read:gpg_key, read:org, read:packages, read:public_key, read:repo_hook, read:user",
33+
"X-Accepted-OAuth-Scopes": "admin:org, read:org, repo, user, write:org",
34+
"X-GitHub-Media-Type": "unknown, github.v3",
35+
"Strict-Transport-Security": "max-age=31536000; includeSubdomains; preload",
36+
"X-Frame-Options": "deny",
37+
"X-Content-Type-Options": "nosniff",
38+
"X-XSS-Protection": "1; mode=block",
39+
"Referrer-Policy": "origin-when-cross-origin, strict-origin-when-cross-origin",
40+
"Content-Security-Policy": "default-src 'none'",
41+
"X-GitHub-Request-Id": "3A75:36154:6E3961D:844DC9F:5EEC5A4A"
42+
}
43+
},
44+
"uuid": "4d3be7ef-fe05-4739-9138-d2050a55a479",
45+
"persistent": true,
46+
"insertionIndex": 2
47+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
{
2+
"id": "7f56b474-35c0-4a6b-82d6-2ebbd5a88725",
3+
"name": "orgs_hub4j-test-org_teams_dummy-team",
4+
"request": {
5+
"url": "/orgs/hub4j-test-org/teams/dummy-team",
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_hub4j-test-org_teams_dummy-team-3.json",
16+
"headers": {
17+
"Date": "Fri, 19 Jun 2020 06:25:15 GMT",
18+
"Content-Type": "application/json; charset=utf-8",
19+
"Server": "GitHub.com",
20+
"Status": "200 OK",
21+
"X-RateLimit-Limit": "5000",
22+
"X-RateLimit-Remaining": "4982",
23+
"X-RateLimit-Reset": "1592551193",
24+
"Cache-Control": "private, max-age=60, s-maxage=60",
25+
"Vary": [
26+
"Accept, Authorization, Cookie, X-GitHub-OTP",
27+
"Accept-Encoding, Accept, X-Requested-With",
28+
"Accept-Encoding"
29+
],
30+
"ETag": "W/\"df4f58bfeba1d4c5945b3dcd4e9579f9\"",
31+
"Last-Modified": "Tue, 02 Jun 2020 19:31:50 GMT",
32+
"X-OAuth-Scopes": "read:discussion, read:enterprise, read:gpg_key, read:org, read:packages, read:public_key, read:repo_hook, read:user",
33+
"X-Accepted-OAuth-Scopes": "admin:org, read:org, repo, user, write:org",
34+
"X-GitHub-Media-Type": "unknown, github.v3",
35+
"Strict-Transport-Security": "max-age=31536000; includeSubdomains; preload",
36+
"X-Frame-Options": "deny",
37+
"X-Content-Type-Options": "nosniff",
38+
"X-XSS-Protection": "1; mode=block",
39+
"Referrer-Policy": "origin-when-cross-origin, strict-origin-when-cross-origin",
40+
"Content-Security-Policy": "default-src 'none'",
41+
"X-GitHub-Request-Id": "3A75:36154:6E3968D:844DE58:5EEC5A4B"
42+
}
43+
},
44+
"uuid": "7f56b474-35c0-4a6b-82d6-2ebbd5a88725",
45+
"persistent": true,
46+
"insertionIndex": 3
47+
}
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
{
2+
"id": "c29c8c17-2529-4266-933e-2fba6569b235",
3+
"name": "teams_3451996_teams",
4+
"request": {
5+
"url": "/teams/3451996/teams",
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": "teams_3451996_teams-4.json",
16+
"headers": {
17+
"Date": "Fri, 19 Jun 2020 06:25:16 GMT",
18+
"Content-Type": "application/json; charset=utf-8",
19+
"Server": "GitHub.com",
20+
"Status": "200 OK",
21+
"X-RateLimit-Limit": "5000",
22+
"X-RateLimit-Remaining": "4981",
23+
"X-RateLimit-Reset": "1592551194",
24+
"Cache-Control": "private, max-age=60, s-maxage=60",
25+
"Vary": [
26+
"Accept, Authorization, Cookie, X-GitHub-OTP",
27+
"Accept-Encoding, Accept, X-Requested-With",
28+
"Accept-Encoding"
29+
],
30+
"ETag": "W/\"0c83b6a8518d93d48b0d72413e32e65b\"",
31+
"X-OAuth-Scopes": "read:discussion, read:enterprise, read:gpg_key, read:org, read:packages, read:public_key, read:repo_hook, read:user",
32+
"X-Accepted-OAuth-Scopes": "admin:org, read:org, repo, user, write:org",
33+
"X-GitHub-Media-Type": "unknown, github.v3",
34+
"Deprecation": "Sat, 01 Feb 2020 00:00:00 GMT",
35+
"Sunset": "Mon, 01 Feb 2021 00:00:00 GMT",
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": "3A75:36154:6E396FD:844DEDD:5EEC5A4B",
43+
"Link": "<https://developer.github.com/changes/2020-01-21-moving-the-team-api-endpoints/>; rel=\"deprecation\"; type=\"text/html\", <https://api.github.com/organizations/7544739/team/3451996/teams>; rel=\"alternate\""
44+
}
45+
},
46+
"uuid": "c29c8c17-2529-4266-933e-2fba6569b235",
47+
"persistent": true,
48+
"insertionIndex": 4
49+
}

0 commit comments

Comments
 (0)