Skip to content

Commit

Permalink
Merge pull request #1395 from gsmet/teams-sunset
Browse files Browse the repository at this point in the history
Switch to the new Teams API
  • Loading branch information
bitwiseman authored Mar 5, 2022
2 parents 358f4ee + 5ff0e46 commit 3c89285
Show file tree
Hide file tree
Showing 461 changed files with 25,202 additions and 20,115 deletions.
11 changes: 9 additions & 2 deletions src/main/java/org/kohsuke/github/GHTeam.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.kohsuke.github;

import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
import org.apache.commons.lang3.StringUtils;

import java.io.IOException;
import java.net.URL;
Expand Down Expand Up @@ -211,7 +212,7 @@ public Set<GHUser> getMembers() throws IOException {
*/
public boolean hasMember(GHUser user) {
try {
root().createRequest().withUrlPath("/teams/" + getId() + "/members/" + user.getLogin()).send();
root().createRequest().withUrlPath(api("/memberships/" + user.getLogin())).send();
return true;
} catch (IOException ignore) {
return false;
Expand Down Expand Up @@ -345,7 +346,13 @@ public void delete() throws IOException {
}

private String api(String tail) {
return "/teams/" + getId() + tail;
if (organization == null) {
// Teams returned from pull requests to do not have an organization. Attempt to use url.
final URL url = Objects.requireNonNull(getUrl(), "Missing instance URL!");
return StringUtils.prependIfMissing(url.toString().replace(root().getApiUrl(), ""), "/") + tail;
}

return "/organizations/" + organization.getId() + "/team/" + getId() + tail;
}

/**
Expand Down
11 changes: 8 additions & 3 deletions src/main/java/org/kohsuke/github/GitHub.java
Original file line number Diff line number Diff line change
Expand Up @@ -874,7 +874,9 @@ public Map<String, Set<GHTeam>> getMyTeams() throws IOException {
}

/**
* Gets a sigle team by ID.
* Gets a single team by ID.
* <p>
* This method is no longer supported and throws an UnsupportedOperationException.
*
* @param id
* the id
Expand All @@ -883,11 +885,14 @@ public Map<String, Set<GHTeam>> getMyTeams() throws IOException {
* the io exception
*
* @deprecated Use {@link GHOrganization#getTeam(long)}
* @see <a href= "https://developer.github.com/v3/teams/#get-team-legacy">deprecation notice</a>
* @see <a href="https://developer.github.com/v3/teams/#get-team-legacy">deprecation notice</a>
* @see <a href="https://github.blog/changelog/2022-02-22-sunset-notice-deprecated-teams-api-endpoints/">sunset
* notice</a>
*/
@Deprecated
public GHTeam getTeam(int id) throws IOException {
return createRequest().withUrlPath("/teams/" + id).fetch(GHTeam.class).wrapUp(this);
throw new UnsupportedOperationException(
"This method is not supported anymore. Please use GHOrganization#getTeam(long).");
}

/**
Expand Down
10 changes: 4 additions & 6 deletions src/test/java/org/kohsuke/github/AppTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import java.util.stream.Collectors;

import static org.hamcrest.Matchers.*;
import static org.junit.Assert.assertThrows;

/**
* Unit test for simple App.
Expand Down Expand Up @@ -444,15 +445,12 @@ private boolean shouldBelongToTeam(String organizationName, String teamName) thr
}

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

GHTeam teamById = gitHub.getTeam((int) teamByName.getId());
assertThat(teamById, notNullValue());

assertThat(teamById.getId(), equalTo(teamByName.getId()));
assertThat(teamById.getDescription(), equalTo(teamByName.getDescription()));
assertThrows(UnsupportedOperationException.class, () -> gitHub.getTeam((int) teamByName.getId()));
}

@Test
Expand Down
4 changes: 3 additions & 1 deletion src/test/java/org/kohsuke/github/GHTeamTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,9 @@ public void listMembersNoMatch() throws IOException {

@Test
public void testSetPrivacy() throws IOException {
String teamSlug = "dummy-team";
// we need to use a team that doesn't have child teams
// as secret privacy is not supported for parent teams
String teamSlug = "simple-team";
Privacy privacy = Privacy.CLOSED;

// Set the privacy.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,31 +20,36 @@
"is_verified": false,
"has_organization_projects": true,
"has_repository_projects": true,
"public_repos": 19,
"public_repos": 49,
"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": 2,
"owned_private_repos": 2,
"total_private_repos": 3,
"owned_private_repos": 3,
"private_gists": 0,
"disk_usage": 11979,
"collaborators": 0,
"billing_email": "[email protected]",
"default_repository_permission": "none",
"members_can_create_repositories": false,
"two_factor_requirement_enabled": false,
"members_allowed_repository_creation_type": "none",
"members_can_create_public_repositories": false,
"members_can_create_private_repositories": false,
"members_can_create_internal_repositories": false,
"members_can_create_pages": true,
"members_can_fork_private_repositories": false,
"members_can_create_public_pages": true,
"members_can_create_private_pages": true,
"plan": {
"name": "free",
"space": 976562499,
"private_repos": 10000,
"filled_seats": 26,
"filled_seats": 35,
"seats": 3
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
[
{
"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"
}
},
{
"name": "Contributors",
"id": 4882699,
"node_id": "MDQ6VGVhbTQ4ODI2OTk=",
"slug": "contributors",
"description": "",
"privacy": "closed",
"url": "https://api.github.com/organizations/7544739/team/4882699",
"html_url": "https://github.com/orgs/hub4j-test-org/teams/contributors",
"members_url": "https://api.github.com/organizations/7544739/team/4882699/members{/member}",
"repositories_url": "https://api.github.com/organizations/7544739/team/4882699/repos",
"permission": "pull",
"parent": null
},
{
"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/hub4j-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": "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",
"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/hub4j-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": "pull",
"parent": null
},
{
"name": "simple-team",
"id": 3947450,
"node_id": "MDQ6VGVhbTM5NDc0NTA=",
"slug": "simple-team",
"description": "A simple team with no children",
"privacy": "secret",
"url": "https://api.github.com/organizations/7544739/team/3947450",
"html_url": "https://github.com/orgs/hub4j-test-org/teams/simple-team",
"members_url": "https://api.github.com/organizations/7544739/team/3947450/members{/member}",
"repositories_url": "https://api.github.com/organizations/7544739/team/3947450/repos",
"permission": "pull",
"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/hub4j-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,47 @@
{
"id": "3c0fb9cd-6289-4f5c-baea-1bd6980a9d15",
"name": "orgs_hub4j-test-org",
"request": {
"url": "/orgs/hub4j-test-org",
"method": "GET",
"headers": {
"Accept": {
"equalTo": "application/vnd.github.v3+json"
}
}
},
"response": {
"status": 200,
"bodyFileName": "orgs_hub4j-test-org-1.json",
"headers": {
"Server": "GitHub.com",
"Date": "Fri, 04 Mar 2022 19:26:44 GMT",
"Content-Type": "application/json; charset=utf-8",
"Cache-Control": "private, max-age=60, s-maxage=60",
"Vary": [
"Accept, Authorization, Cookie, X-GitHub-OTP",
"Accept-Encoding, Accept, X-Requested-With"
],
"ETag": "W/\"861b38147d37bd59e507771e76ec048def20dd6e5ac5b75aceb01c8b9f0ef4f5\"",
"Last-Modified": "Thu, 04 Jun 2020 05:56:10 GMT",
"X-OAuth-Scopes": "admin:gpg_key, admin:org, admin:org_hook, admin:public_key, admin:repo_hook, gist, notifications, repo, user, workflow, write:discussion",
"X-Accepted-OAuth-Scopes": "admin:org, read:org, repo, user, write:org",
"X-GitHub-Media-Type": "github.v3; format=json",
"X-RateLimit-Limit": "5000",
"X-RateLimit-Remaining": "4998",
"X-RateLimit-Reset": "1646424320",
"X-RateLimit-Used": "2",
"X-RateLimit-Resource": "core",
"Strict-Transport-Security": "max-age=31536000; includeSubdomains; preload",
"X-Frame-Options": "deny",
"X-Content-Type-Options": "nosniff",
"X-XSS-Protection": "0",
"Referrer-Policy": "origin-when-cross-origin, strict-origin-when-cross-origin",
"Content-Security-Policy": "default-src 'none'",
"X-GitHub-Request-Id": "B678:265F:2A24E9B:2AE23A8:622267F3"
}
},
"uuid": "3c0fb9cd-6289-4f5c-baea-1bd6980a9d15",
"persistent": true,
"insertionIndex": 1
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"id": "d833590f-9896-462c-846b-712b50377536",
"id": "ea1f3852-66f4-4238-b721-34f584b153dd",
"name": "orgs_hub4j-test-org_teams",
"request": {
"url": "/orgs/hub4j-test-org/teams",
Expand All @@ -12,34 +12,35 @@
},
"response": {
"status": 200,
"bodyFileName": "orgs_hub4j-test-org_teams-3.json",
"bodyFileName": "orgs_hub4j-test-org_teams-2.json",
"headers": {
"Date": "Tue, 17 Mar 2020 10:05:32 GMT",
"Content-Type": "application/json; charset=utf-8",
"Server": "GitHub.com",
"Status": "200 OK",
"X-RateLimit-Limit": "5000",
"X-RateLimit-Remaining": "4936",
"X-RateLimit-Reset": "1584440312",
"Date": "Fri, 04 Mar 2022 19:26:44 GMT",
"Content-Type": "application/json; charset=utf-8",
"Cache-Control": "private, max-age=60, s-maxage=60",
"Vary": [
"Accept, Authorization, Cookie, X-GitHub-OTP",
"Accept-Encoding, Accept, X-Requested-With"
],
"ETag": "W/\"54e42fc30d88d2a30340b56bbe54f211\"",
"X-OAuth-Scopes": "admin:org, admin:public_key, admin:repo_hook, notifications, repo, user",
"ETag": "W/\"1964a2ad48a21e85f64539404f5b8da870c58d1e9f3f8cf1b2dd8b6969b2c909\"",
"X-OAuth-Scopes": "admin:gpg_key, admin:org, admin:org_hook, admin:public_key, admin:repo_hook, gist, notifications, repo, user, workflow, write:discussion",
"X-Accepted-OAuth-Scopes": "admin:org, read:org, repo, user, write:org",
"X-GitHub-Media-Type": "unknown, github.v3",
"X-GitHub-Media-Type": "github.v3; format=json",
"X-RateLimit-Limit": "5000",
"X-RateLimit-Remaining": "4997",
"X-RateLimit-Reset": "1646424320",
"X-RateLimit-Used": "3",
"X-RateLimit-Resource": "core",
"Strict-Transport-Security": "max-age=31536000; includeSubdomains; preload",
"X-Frame-Options": "deny",
"X-Content-Type-Options": "nosniff",
"X-XSS-Protection": "1; mode=block",
"X-XSS-Protection": "0",
"Referrer-Policy": "origin-when-cross-origin, strict-origin-when-cross-origin",
"Content-Security-Policy": "default-src 'none'",
"X-GitHub-Request-Id": "FBBC:4FD5:1C7963:325E5F:5E70A0EC"
"X-GitHub-Request-Id": "B67A:2658:7E2214:85CE23:622267F4"
}
},
"uuid": "d833590f-9896-462c-846b-712b50377536",
"uuid": "ea1f3852-66f4-4238-b721-34f584b153dd",
"persistent": true,
"insertionIndex": 3
"insertionIndex": 2
}
Loading

0 comments on commit 3c89285

Please sign in to comment.