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

Added support for fetching what teams are part of this team. #849

Merged
merged 6 commits into from
Jul 15, 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
13 changes: 13 additions & 0 deletions src/main/java/org/kohsuke/github/GHTeam.java
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,19 @@ public PagedIterable<GHUser> listMembers() throws IOException {
return root.createRequest().withUrlPath(api("/members")).toIterable(GHUser[].class, item -> item.wrapUp(root));
}

/**
* Retrieves the teams that are children of this team.
*
* @return the paged iterable
* @throws IOException
* the io exception
*/
public PagedIterable<GHTeam> listChildTeams() throws IOException {
return root.createRequest()
.withUrlPath(api("/teams"))
.toIterable(GHTeam[].class, item -> item.wrapUp(this.organization));
}

/**
* Gets members.
*
Expand Down
24 changes: 24 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.Set;

import static org.junit.Assert.assertEquals;

Expand Down Expand Up @@ -56,4 +57,27 @@ public void testSetPrivacy() throws IOException {
assertEquals(privacy, team.getPrivacy());
}

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

GHOrganization org = gitHub.getOrganization(GITHUB_API_TEST_ORG);
GHTeam team = org.getTeamBySlug(teamSlug);
Set<GHTeam> result = team.listChildTeams().toSet();

assertEquals(1, result.size());
assertEquals("child-team-for-dummy", result.toArray(new GHTeam[]{})[0].getName());
}

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

GHOrganization org = gitHub.getOrganization(GITHUB_API_TEST_ORG);
GHTeam team = org.getTeamBySlug(teamSlug);
Set<GHTeam> result = team.listChildTeams().toSet();

assertEquals(0, result.size());
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
{
"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": 12,
"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": 0,
"owned_private_repos": 0,
"private_gists": null,
"disk_usage": null,
"collaborators": null,
"billing_email": null,
"default_repository_permission": null,
"members_can_create_repositories": false,
"two_factor_requirement_enabled": null,
"plan": {
"name": "free",
"space": 976562499,
"private_repos": 10000,
"filled_seats": 19,
"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": 2,
"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": 12,
"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,28 @@
[
{
"name": "child-team-for-dummy",
"id": 3903497,
"node_id": "MDQ6VGVhbTM5MDM0OTc=",
"slug": "child-team-for-dummy",
"description": "to test the fetching of child teams",
"privacy": "closed",
"url": "https://api.github.com/organizations/7544739/team/3903497",
"html_url": "https://github.com/orgs/hub4j-test-org/teams/child-team-for-dummy",
"members_url": "https://api.github.com/organizations/7544739/team/3903497/members{/member}",
"repositories_url": "https://api.github.com/organizations/7544739/team/3903497/repos",
"permission": "pull",
"parent": {
"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"
}
}
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
{
"login": "alexanderkjall",
"id": 647710,
"node_id": "MDQ6VXNlcjY0NzcxMA==",
"avatar_url": "https://avatars2.githubusercontent.com/u/647710?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/alexanderkjall",
"html_url": "https://github.com/alexanderkjall",
"followers_url": "https://api.github.com/users/alexanderkjall/followers",
"following_url": "https://api.github.com/users/alexanderkjall/following{/other_user}",
"gists_url": "https://api.github.com/users/alexanderkjall/gists{/gist_id}",
"starred_url": "https://api.github.com/users/alexanderkjall/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/alexanderkjall/subscriptions",
"organizations_url": "https://api.github.com/users/alexanderkjall/orgs",
"repos_url": "https://api.github.com/users/alexanderkjall/repos",
"events_url": "https://api.github.com/users/alexanderkjall/events{/privacy}",
"received_events_url": "https://api.github.com/users/alexanderkjall/received_events",
"type": "User",
"site_admin": false,
"name": "Alexander Kjäll",
"company": "DI",
"blog": "",
"location": "Oslo",
"email": "alexander.kjall@gmail.com",
"hireable": null,
"bio": null,
"twitter_username": null,
"public_repos": 56,
"public_gists": 6,
"followers": 10,
"following": 7,
"created_at": "2011-03-02T20:31:15Z",
"updated_at": "2020-06-19T06:10:45Z",
"private_gists": 1,
"total_private_repos": 1,
"owned_private_repos": 1,
"disk_usage": 46941,
"collaborators": 0,
"two_factor_authentication": true,
"plan": {
"name": "free",
"space": 976562499,
"collaborators": 0,
"private_repos": 10000
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
{
"id": "4d3be7ef-fe05-4739-9138-d2050a55a479",
"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-2.json",
"headers": {
"Date": "Fri, 19 Jun 2020 06:25:15 GMT",
"Content-Type": "application/json; charset=utf-8",
"Server": "GitHub.com",
"Status": "200 OK",
"X-RateLimit-Limit": "5000",
"X-RateLimit-Remaining": "4983",
"X-RateLimit-Reset": "1592551194",
"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/\"1cf57cb32512ca7f96e2d9133ecbb8e4\"",
"Last-Modified": "Thu, 04 Jun 2020 05:56:10 GMT",
"X-OAuth-Scopes": "read:discussion, read:enterprise, read:gpg_key, read:org, read:packages, read:public_key, read:repo_hook, read:user",
"X-Accepted-OAuth-Scopes": "admin:org, read:org, repo, user, write:org",
"X-GitHub-Media-Type": "unknown, github.v3",
"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": "3A75:36154:6E3961D:844DC9F:5EEC5A4A"
}
},
"uuid": "4d3be7ef-fe05-4739-9138-d2050a55a479",
"persistent": true,
"insertionIndex": 2
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
{
"id": "7f56b474-35c0-4a6b-82d6-2ebbd5a88725",
"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-3.json",
"headers": {
"Date": "Fri, 19 Jun 2020 06:25:15 GMT",
"Content-Type": "application/json; charset=utf-8",
"Server": "GitHub.com",
"Status": "200 OK",
"X-RateLimit-Limit": "5000",
"X-RateLimit-Remaining": "4982",
"X-RateLimit-Reset": "1592551193",
"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/\"df4f58bfeba1d4c5945b3dcd4e9579f9\"",
"Last-Modified": "Tue, 02 Jun 2020 19:31:50 GMT",
"X-OAuth-Scopes": "read:discussion, read:enterprise, read:gpg_key, read:org, read:packages, read:public_key, read:repo_hook, read:user",
"X-Accepted-OAuth-Scopes": "admin:org, read:org, repo, user, write:org",
"X-GitHub-Media-Type": "unknown, github.v3",
"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": "3A75:36154:6E3968D:844DE58:5EEC5A4B"
}
},
"uuid": "7f56b474-35c0-4a6b-82d6-2ebbd5a88725",
"persistent": true,
"insertionIndex": 3
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
{
"id": "c29c8c17-2529-4266-933e-2fba6569b235",
"name": "teams_3451996_teams",
"request": {
"url": "/teams/3451996/teams",
"method": "GET",
"headers": {
"Accept": {
"equalTo": "text/html, image/gif, image/jpeg, *; q=.2, */*; q=.2"
}
}
},
"response": {
"status": 200,
"bodyFileName": "teams_3451996_teams-4.json",
"headers": {
"Date": "Fri, 19 Jun 2020 06:25:16 GMT",
"Content-Type": "application/json; charset=utf-8",
"Server": "GitHub.com",
"Status": "200 OK",
"X-RateLimit-Limit": "5000",
"X-RateLimit-Remaining": "4981",
"X-RateLimit-Reset": "1592551194",
"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/\"0c83b6a8518d93d48b0d72413e32e65b\"",
"X-OAuth-Scopes": "read:discussion, read:enterprise, read:gpg_key, read:org, read:packages, read:public_key, read:repo_hook, read:user",
"X-Accepted-OAuth-Scopes": "admin:org, read:org, repo, user, write:org",
"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",
"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": "3A75:36154:6E396FD:844DEDD:5EEC5A4B",
"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\""
}
},
"uuid": "c29c8c17-2529-4266-933e-2fba6569b235",
"persistent": true,
"insertionIndex": 4
}
Loading