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
30 changes: 24 additions & 6 deletions src/main/java/org/kohsuke/github/GHOrganization.java
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,24 @@ public PagedIterable<GHTeam> listTeams() throws IOException {
.toIterable(GHTeam[].class, item -> item.wrapUp(this));
}

/**
* Gets a single team by ID.
*
* @param teamId
* id of the team that we want to query for
* @return the team
* @throws IOException
* the io exception
*
* @see <a href= "https://developer.github.com/v3/teams/#get-team-by-name">documentation</a>
*/
public GHTeam getTeam(int teamId) throws IOException {
return root.createRequest()
.withUrlPath(String.format("/organizations/%d/team/%d", id, teamId))
.fetch(GHTeam.class)
.wrapUp(this);
}

/**
* Finds a team that has the given name in its {@link GHTeam#getName()}
*
Expand All @@ -147,19 +165,19 @@ public GHTeam getTeamByName(String name) throws IOException {

/**
* Finds a team that has the given slug in its {@link GHTeam#getSlug()}
*
*
* @param slug
* the slug
* @return the team by slug
* @throws IOException
* the io exception
* @see <a href= "https://developer.github.com/v3/teams/#get-team-by-name">documentation</a>
*/
public GHTeam getTeamBySlug(String slug) throws IOException {
for (GHTeam t : listTeams()) {
if (t.getSlug().equals(slug))
return t;
}
return null;
return root.createRequest()
.withUrlPath(String.format("/orgs/%s/teams/%s", login, slug))
.fetch(GHTeam.class)
.wrapUp(this);
}

/**
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/org/kohsuke/github/GitHub.java
Original file line number Diff line number Diff line change
Expand Up @@ -724,7 +724,11 @@ public Map<String, Set<GHTeam>> getMyTeams() throws IOException {
* @return the team
* @throws IOException
* the io exception
*
* @deprecated Use {@link GHOrganization#getTeam(int)}
* @see <a href= "https://developer.github.com/v3/teams/#get-team-legacy">deprecation notice</a>
*/
@Deprecated
public GHTeam getTeam(int id) throws IOException {
return createRequest().withUrlPath("/teams/" + id).fetch(GHTeam.class).wrapUp(this);
}
Expand Down
20 changes: 16 additions & 4 deletions src/test/java/org/kohsuke/github/AppTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -234,16 +234,28 @@ private boolean shouldBelongToTeam(String organizationName, String teamName) thr
return team.hasMember(gitHub.getMyself());
}

@Ignore("Needs mocking check")
@Test
public void testShouldFetchTeam() throws Exception {
GHOrganization j = gitHub.getOrganization(GITHUB_API_TEST_ORG);
GHTeam teamByName = j.getTeams().get("Core Developers");
GHOrganization organization = gitHub.getOrganization(GITHUB_API_TEST_ORG);
GHTeam teamByName = organization.getTeams().get("Core Developers");

GHTeam teamById = gitHub.getTeam(teamByName.getId());
Copy link
Member

Choose a reason for hiding this comment

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

Sorry, just because it is deprecated doesn't mean we can remove the test for it. We must ensure it continues to work until it is removed.

assertNotNull(teamById);

assertEquals(teamByName, teamById);
assertEquals(teamByName.getId(), teamById.getId());
assertEquals(teamByName.getDescription(), teamById.getDescription());
}

@Test
public void testShouldFetchTeamFromOrganization() throws Exception {
GHOrganization organization = gitHub.getOrganization(GITHUB_API_TEST_ORG);
GHTeam teamByName = organization.getTeams().get("Core Developers");

GHTeam teamById = organization.getTeam(teamByName.getId());
assertNotNull(teamById);

assertEquals(teamByName.getId(), teamById.getId());
assertEquals(teamByName.getDescription(), teamById.getDescription());
}

@Ignore("Needs mocking check")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,8 @@ public void BasicBehaviors_whenProxying() throws Exception {

assertThat(e, Matchers.<Exception>instanceOf(GHFileNotFoundException.class));
assertThat(e.getMessage(),
equalTo("{\"message\":\"Not Found\",\"documentation_url\":\"https://developer.github.com/v3/repos/#get\"}"));
containsString(
"{\"message\":\"Not Found\",\"documentation_url\":\"https://developer.github.com/v3/repos/#get\"}"));
}

@Test
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
{
"name": "Core Developers",
"id": 820406,
"node_id": "MDQ6VGVhbTgyMDQwNg==",
"slug": "core-developers",
"description": "A random team",
"privacy": "secret",
"url": "https://api.github.com/organizations/7544739/team/820406",
"html_url": "https://github.com/orgs/github-api-test-org/teams/core-developers",
"members_url": "https://api.github.com/organizations/7544739/team/820406/members{/member}",
"repositories_url": "https://api.github.com/organizations/7544739/team/820406/repos",
"permission": "pull",
"created_at": "2014-05-10T19:40:03Z",
"updated_at": "2014-05-10T19:40:03Z",
"members_count": 1,
"repos_count": 1,
"organization": {
"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": 26,
"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"
},
"parent": null
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
{
"id": "b7236bc9-4447-4721-acdb-7598066525d6",
"name": "orgs_github-api-test-org_teams_core-developers",
"request": {
"url": "/orgs/github-api-test-org/teams/core-developers",
"method": "GET",
"headers": {
"Accept": {
"equalTo": "text/html, image/gif, image/jpeg, *; q=.2, */*; q=.2"
}
}
},
"response": {
"status": 200,
"bodyFileName": "orgs_github-api-test-org_teams_core-developers-b7236bc9-4447-4721-acdb-7598066525d6.json",
"headers": {
"Date": "Tue, 17 Mar 2020 09:18:50 GMT",
"Content-Type": "application/json; charset=utf-8",
"Server": "GitHub.com",
"Status": "200 OK",
"X-RateLimit-Limit": "5000",
"X-RateLimit-Remaining": "4995",
"X-RateLimit-Reset": "1584440312",
"Cache-Control": "private, max-age=60, s-maxage=60",
"Vary": [
"Accept, Authorization, Cookie, X-GitHub-OTP",
"Accept-Encoding, Accept, X-Requested-With"
],
"ETag": "W/\"1201d96396c062b2208db689dc6a3887\"",
"Last-Modified": "Sat, 10 May 2014 19:40:03 GMT",
"X-OAuth-Scopes": "admin:org, admin:public_key, admin:repo_hook, notifications, repo, 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": "F97C:520F:195318:2E8EA9:5E7095FA"
}
},
"uuid": "b7236bc9-4447-4721-acdb-7598066525d6",
"persistent": true,
"insertionIndex": 4
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
{
"name": "Core Developers",
"id": 820406,
"node_id": "MDQ6VGVhbTgyMDQwNg==",
"slug": "core-developers",
"description": "A random team",
"privacy": "secret",
"url": "https://api.github.com/organizations/7544739/team/820406",
"html_url": "https://github.com/orgs/github-api-test-org/teams/core-developers",
"members_url": "https://api.github.com/organizations/7544739/team/820406/members{/member}",
"repositories_url": "https://api.github.com/organizations/7544739/team/820406/repos",
"permission": "pull",
"created_at": "2014-05-10T19:40:03Z",
"updated_at": "2014-05-10T19:40:03Z",
"members_count": 1,
"repos_count": 1,
"organization": {
"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": 26,
"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"
},
"parent": null
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"is_verified": false,
"has_organization_projects": true,
"has_repository_projects": true,
"public_repos": 9,
"public_repos": 26,
"public_gists": 0,
"followers": 0,
"following": 0,
Expand All @@ -25,7 +25,7 @@
"total_private_repos": 0,
"owned_private_repos": 0,
"private_gists": 0,
"disk_usage": 132,
"disk_usage": 147,
"collaborators": 0,
"billing_email": "kk@kohsuke.org",
"default_repository_permission": "none",
Expand All @@ -35,7 +35,7 @@
"name": "free",
"space": 976562499,
"private_repos": 0,
"filled_seats": 3,
"filled_seats": 13,
"seats": 0
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
[
{
"name": "Core Developers",
"id": 820406,
"node_id": "MDQ6VGVhbTgyMDQwNg==",
"slug": "core-developers",
"description": "A random team",
"privacy": "secret",
"url": "https://api.github.com/organizations/7544739/team/820406",
"html_url": "https://github.com/orgs/github-api-test-org/teams/core-developers",
"members_url": "https://api.github.com/organizations/7544739/team/820406/members{/member}",
"repositories_url": "https://api.github.com/organizations/7544739/team/820406/repos",
"permission": "pull",
"parent": null
},
{
"name": "dummy-team",
"id": 3451996,
"node_id": "MDQ6VGVhbTM0NTE5OTY=",
"slug": "dummy-team",
"description": "Updated by API TestModified",
"privacy": "secret",
"url": "https://api.github.com/organizations/7544739/team/3451996",
"html_url": "https://github.com/orgs/github-api-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",
"parent": null
},
{
"name": "Owners-team",
"id": 820404,
"node_id": "MDQ6VGVhbTgyMDQwNA==",
"slug": "owners-team",
"description": null,
"privacy": "secret",
"url": "https://api.github.com/organizations/7544739/team/820404",
"html_url": "https://github.com/orgs/github-api-test-org/teams/owners-team",
"members_url": "https://api.github.com/organizations/7544739/team/820404/members{/member}",
"repositories_url": "https://api.github.com/organizations/7544739/team/820404/repos",
"permission": "admin",
"parent": null
},
{
"name": "tricky-team",
"id": 3454508,
"node_id": "MDQ6VGVhbTM0NTQ1MDg=",
"slug": "tricky-team",
"description": "",
"privacy": "secret",
"url": "https://api.github.com/organizations/7544739/team/3454508",
"html_url": "https://github.com/orgs/github-api-test-org/teams/tricky-team",
"members_url": "https://api.github.com/organizations/7544739/team/3454508/members{/member}",
"repositories_url": "https://api.github.com/organizations/7544739/team/3454508/repos",
"permission": "pull",
"parent": null
}
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
{
"name": "Core Developers",
"id": 820406,
"node_id": "MDQ6VGVhbTgyMDQwNg==",
"slug": "core-developers",
"description": "A random team",
"privacy": "secret",
"url": "https://api.github.com/organizations/7544739/team/820406",
"html_url": "https://github.com/orgs/github-api-test-org/teams/core-developers",
"members_url": "https://api.github.com/organizations/7544739/team/820406/members{/member}",
"repositories_url": "https://api.github.com/organizations/7544739/team/820406/repos",
"permission": "pull",
"created_at": "2014-05-10T19:40:03Z",
"updated_at": "2014-05-10T19:40:03Z",
"members_count": 1,
"repos_count": 1,
"organization": {
"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": 26,
"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"
},
"parent": null
}
Loading