Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 3c89285

Browse filesBrowse files
authored
Merge pull request hub4j#1395 from gsmet/teams-sunset
Switch to the new Teams API
2 parents 358f4ee + 5ff0e46 commit 3c89285
Copy full SHA for 3c89285

File tree

Expand file treeCollapse file tree

461 files changed

+25202
-20115
lines changed
Filter options

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
Dismiss banner
Expand file treeCollapse file tree

461 files changed

+25202
-20115
lines changed

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

Copy file name to clipboardExpand all lines: src/main/java/org/kohsuke/github/GHTeam.java
+9-2Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package org.kohsuke.github;
22

33
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
4+
import org.apache.commons.lang3.StringUtils;
45

56
import java.io.IOException;
67
import java.net.URL;
@@ -211,7 +212,7 @@ public Set<GHUser> getMembers() throws IOException {
211212
*/
212213
public boolean hasMember(GHUser user) {
213214
try {
214-
root().createRequest().withUrlPath("/teams/" + getId() + "/members/" + user.getLogin()).send();
215+
root().createRequest().withUrlPath(api("/memberships/" + user.getLogin())).send();
215216
return true;
216217
} catch (IOException ignore) {
217218
return false;
@@ -345,7 +346,13 @@ public void delete() throws IOException {
345346
}
346347

347348
private String api(String tail) {
348-
return "/teams/" + getId() + tail;
349+
if (organization == null) {
350+
// Teams returned from pull requests to do not have an organization. Attempt to use url.
351+
final URL url = Objects.requireNonNull(getUrl(), "Missing instance URL!");
352+
return StringUtils.prependIfMissing(url.toString().replace(root().getApiUrl(), ""), "/") + tail;
353+
}
354+
355+
return "/organizations/" + organization.getId() + "/team/" + getId() + tail;
349356
}
350357

351358
/**

‎src/main/java/org/kohsuke/github/GitHub.java

Copy file name to clipboardExpand all lines: src/main/java/org/kohsuke/github/GitHub.java
+8-3Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -874,7 +874,9 @@ public Map<String, Set<GHTeam>> getMyTeams() throws IOException {
874874
}
875875

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

893898
/**

‎src/test/java/org/kohsuke/github/AppTest.java

Copy file name to clipboardExpand all lines: src/test/java/org/kohsuke/github/AppTest.java
+4-6Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import java.util.stream.Collectors;
2222

2323
import static org.hamcrest.Matchers.*;
24+
import static org.junit.Assert.assertThrows;
2425

2526
/**
2627
* Unit test for simple App.
@@ -444,15 +445,12 @@ private boolean shouldBelongToTeam(String organizationName, String teamName) thr
444445
}
445446

446447
@Test
447-
public void testShouldFetchTeam() throws Exception {
448+
@SuppressWarnings("deprecation")
449+
public void testFetchingTeamFromGitHubInstanceThrowsException() throws Exception {
448450
GHOrganization organization = gitHub.getOrganization(GITHUB_API_TEST_ORG);
449451
GHTeam teamByName = organization.getTeams().get("Core Developers");
450452

451-
GHTeam teamById = gitHub.getTeam((int) teamByName.getId());
452-
assertThat(teamById, notNullValue());
453-
454-
assertThat(teamById.getId(), equalTo(teamByName.getId()));
455-
assertThat(teamById.getDescription(), equalTo(teamByName.getDescription()));
453+
assertThrows(UnsupportedOperationException.class, () -> gitHub.getTeam((int) teamByName.getId()));
456454
}
457455

458456
@Test

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

Copy file name to clipboardExpand all lines: src/test/java/org/kohsuke/github/GHTeamTest.java
+3-1Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,9 @@ public void listMembersNoMatch() throws IOException {
9191

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

9799
// Set the privacy.

‎src/test/resources/org/kohsuke/github/GHTeamTest/wiremock/listMembers/__files/orgs_hub4j-test-org-2.json renamed to ‎src/test/resources/org/kohsuke/github/AppTest/wiremock/testFetchingTeamFromGitHubInstanceThrowsException/__files/orgs_hub4j-test-org-1.json

Copy file name to clipboardExpand all lines: src/test/resources/org/kohsuke/github/AppTest/wiremock/testFetchingTeamFromGitHubInstanceThrowsException/__files/orgs_hub4j-test-org-1.json
+9-4Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,31 +20,36 @@
2020
"is_verified": false,
2121
"has_organization_projects": true,
2222
"has_repository_projects": true,
23-
"public_repos": 19,
23+
"public_repos": 49,
2424
"public_gists": 0,
2525
"followers": 0,
2626
"following": 0,
2727
"html_url": "https://github.com/hub4j-test-org",
2828
"created_at": "2014-05-10T19:39:11Z",
2929
"updated_at": "2020-06-04T05:56:10Z",
3030
"type": "Organization",
31-
"total_private_repos": 2,
32-
"owned_private_repos": 2,
31+
"total_private_repos": 3,
32+
"owned_private_repos": 3,
3333
"private_gists": 0,
3434
"disk_usage": 11979,
3535
"collaborators": 0,
3636
"billing_email": "kk@kohsuke.org",
3737
"default_repository_permission": "none",
3838
"members_can_create_repositories": false,
3939
"two_factor_requirement_enabled": false,
40+
"members_allowed_repository_creation_type": "none",
41+
"members_can_create_public_repositories": false,
42+
"members_can_create_private_repositories": false,
43+
"members_can_create_internal_repositories": false,
4044
"members_can_create_pages": true,
45+
"members_can_fork_private_repositories": false,
4146
"members_can_create_public_pages": true,
4247
"members_can_create_private_pages": true,
4348
"plan": {
4449
"name": "free",
4550
"space": 976562499,
4651
"private_repos": 10000,
47-
"filled_seats": 26,
52+
"filled_seats": 35,
4853
"seats": 3
4954
}
5055
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
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+
{
29+
"name": "Contributors",
30+
"id": 4882699,
31+
"node_id": "MDQ6VGVhbTQ4ODI2OTk=",
32+
"slug": "contributors",
33+
"description": "",
34+
"privacy": "closed",
35+
"url": "https://api.github.com/organizations/7544739/team/4882699",
36+
"html_url": "https://github.com/orgs/hub4j-test-org/teams/contributors",
37+
"members_url": "https://api.github.com/organizations/7544739/team/4882699/members{/member}",
38+
"repositories_url": "https://api.github.com/organizations/7544739/team/4882699/repos",
39+
"permission": "pull",
40+
"parent": null
41+
},
42+
{
43+
"name": "Core Developers",
44+
"id": 820406,
45+
"node_id": "MDQ6VGVhbTgyMDQwNg==",
46+
"slug": "core-developers",
47+
"description": "A random team",
48+
"privacy": "secret",
49+
"url": "https://api.github.com/organizations/7544739/team/820406",
50+
"html_url": "https://github.com/orgs/hub4j-test-org/teams/core-developers",
51+
"members_url": "https://api.github.com/organizations/7544739/team/820406/members{/member}",
52+
"repositories_url": "https://api.github.com/organizations/7544739/team/820406/repos",
53+
"permission": "pull",
54+
"parent": null
55+
},
56+
{
57+
"name": "dummy-team",
58+
"id": 3451996,
59+
"node_id": "MDQ6VGVhbTM0NTE5OTY=",
60+
"slug": "dummy-team",
61+
"description": "Updated by API TestModified",
62+
"privacy": "closed",
63+
"url": "https://api.github.com/organizations/7544739/team/3451996",
64+
"html_url": "https://github.com/orgs/hub4j-test-org/teams/dummy-team",
65+
"members_url": "https://api.github.com/organizations/7544739/team/3451996/members{/member}",
66+
"repositories_url": "https://api.github.com/organizations/7544739/team/3451996/repos",
67+
"permission": "pull",
68+
"parent": null
69+
},
70+
{
71+
"name": "Owners-team",
72+
"id": 820404,
73+
"node_id": "MDQ6VGVhbTgyMDQwNA==",
74+
"slug": "owners-team",
75+
"description": null,
76+
"privacy": "secret",
77+
"url": "https://api.github.com/organizations/7544739/team/820404",
78+
"html_url": "https://github.com/orgs/hub4j-test-org/teams/owners-team",
79+
"members_url": "https://api.github.com/organizations/7544739/team/820404/members{/member}",
80+
"repositories_url": "https://api.github.com/organizations/7544739/team/820404/repos",
81+
"permission": "pull",
82+
"parent": null
83+
},
84+
{
85+
"name": "simple-team",
86+
"id": 3947450,
87+
"node_id": "MDQ6VGVhbTM5NDc0NTA=",
88+
"slug": "simple-team",
89+
"description": "A simple team with no children",
90+
"privacy": "secret",
91+
"url": "https://api.github.com/organizations/7544739/team/3947450",
92+
"html_url": "https://github.com/orgs/hub4j-test-org/teams/simple-team",
93+
"members_url": "https://api.github.com/organizations/7544739/team/3947450/members{/member}",
94+
"repositories_url": "https://api.github.com/organizations/7544739/team/3947450/repos",
95+
"permission": "pull",
96+
"parent": null
97+
},
98+
{
99+
"name": "tricky-team",
100+
"id": 3454508,
101+
"node_id": "MDQ6VGVhbTM0NTQ1MDg=",
102+
"slug": "tricky-team",
103+
"description": "",
104+
"privacy": "secret",
105+
"url": "https://api.github.com/organizations/7544739/team/3454508",
106+
"html_url": "https://github.com/orgs/hub4j-test-org/teams/tricky-team",
107+
"members_url": "https://api.github.com/organizations/7544739/team/3454508/members{/member}",
108+
"repositories_url": "https://api.github.com/organizations/7544739/team/3454508/repos",
109+
"permission": "pull",
110+
"parent": null
111+
}
112+
]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
{
2+
"id": "3c0fb9cd-6289-4f5c-baea-1bd6980a9d15",
3+
"name": "orgs_hub4j-test-org",
4+
"request": {
5+
"url": "/orgs/hub4j-test-org",
6+
"method": "GET",
7+
"headers": {
8+
"Accept": {
9+
"equalTo": "application/vnd.github.v3+json"
10+
}
11+
}
12+
},
13+
"response": {
14+
"status": 200,
15+
"bodyFileName": "orgs_hub4j-test-org-1.json",
16+
"headers": {
17+
"Server": "GitHub.com",
18+
"Date": "Fri, 04 Mar 2022 19:26:44 GMT",
19+
"Content-Type": "application/json; charset=utf-8",
20+
"Cache-Control": "private, max-age=60, s-maxage=60",
21+
"Vary": [
22+
"Accept, Authorization, Cookie, X-GitHub-OTP",
23+
"Accept-Encoding, Accept, X-Requested-With"
24+
],
25+
"ETag": "W/\"861b38147d37bd59e507771e76ec048def20dd6e5ac5b75aceb01c8b9f0ef4f5\"",
26+
"Last-Modified": "Thu, 04 Jun 2020 05:56:10 GMT",
27+
"X-OAuth-Scopes": "admin:gpg_key, admin:org, admin:org_hook, admin:public_key, admin:repo_hook, gist, notifications, repo, user, workflow, write:discussion",
28+
"X-Accepted-OAuth-Scopes": "admin:org, read:org, repo, user, write:org",
29+
"X-GitHub-Media-Type": "github.v3; format=json",
30+
"X-RateLimit-Limit": "5000",
31+
"X-RateLimit-Remaining": "4998",
32+
"X-RateLimit-Reset": "1646424320",
33+
"X-RateLimit-Used": "2",
34+
"X-RateLimit-Resource": "core",
35+
"Strict-Transport-Security": "max-age=31536000; includeSubdomains; preload",
36+
"X-Frame-Options": "deny",
37+
"X-Content-Type-Options": "nosniff",
38+
"X-XSS-Protection": "0",
39+
"Referrer-Policy": "origin-when-cross-origin, strict-origin-when-cross-origin",
40+
"Content-Security-Policy": "default-src 'none'",
41+
"X-GitHub-Request-Id": "B678:265F:2A24E9B:2AE23A8:622267F3"
42+
}
43+
},
44+
"uuid": "3c0fb9cd-6289-4f5c-baea-1bd6980a9d15",
45+
"persistent": true,
46+
"insertionIndex": 1
47+
}
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"id": "d833590f-9896-462c-846b-712b50377536",
2+
"id": "ea1f3852-66f4-4238-b721-34f584b153dd",
33
"name": "orgs_hub4j-test-org_teams",
44
"request": {
55
"url": "/orgs/hub4j-test-org/teams",
@@ -12,34 +12,35 @@
1212
},
1313
"response": {
1414
"status": 200,
15-
"bodyFileName": "orgs_hub4j-test-org_teams-3.json",
15+
"bodyFileName": "orgs_hub4j-test-org_teams-2.json",
1616
"headers": {
17-
"Date": "Tue, 17 Mar 2020 10:05:32 GMT",
18-
"Content-Type": "application/json; charset=utf-8",
1917
"Server": "GitHub.com",
20-
"Status": "200 OK",
21-
"X-RateLimit-Limit": "5000",
22-
"X-RateLimit-Remaining": "4936",
23-
"X-RateLimit-Reset": "1584440312",
18+
"Date": "Fri, 04 Mar 2022 19:26:44 GMT",
19+
"Content-Type": "application/json; charset=utf-8",
2420
"Cache-Control": "private, max-age=60, s-maxage=60",
2521
"Vary": [
2622
"Accept, Authorization, Cookie, X-GitHub-OTP",
2723
"Accept-Encoding, Accept, X-Requested-With"
2824
],
29-
"ETag": "W/\"54e42fc30d88d2a30340b56bbe54f211\"",
30-
"X-OAuth-Scopes": "admin:org, admin:public_key, admin:repo_hook, notifications, repo, user",
25+
"ETag": "W/\"1964a2ad48a21e85f64539404f5b8da870c58d1e9f3f8cf1b2dd8b6969b2c909\"",
26+
"X-OAuth-Scopes": "admin:gpg_key, admin:org, admin:org_hook, admin:public_key, admin:repo_hook, gist, notifications, repo, user, workflow, write:discussion",
3127
"X-Accepted-OAuth-Scopes": "admin:org, read:org, repo, user, write:org",
32-
"X-GitHub-Media-Type": "unknown, github.v3",
28+
"X-GitHub-Media-Type": "github.v3; format=json",
29+
"X-RateLimit-Limit": "5000",
30+
"X-RateLimit-Remaining": "4997",
31+
"X-RateLimit-Reset": "1646424320",
32+
"X-RateLimit-Used": "3",
33+
"X-RateLimit-Resource": "core",
3334
"Strict-Transport-Security": "max-age=31536000; includeSubdomains; preload",
3435
"X-Frame-Options": "deny",
3536
"X-Content-Type-Options": "nosniff",
36-
"X-XSS-Protection": "1; mode=block",
37+
"X-XSS-Protection": "0",
3738
"Referrer-Policy": "origin-when-cross-origin, strict-origin-when-cross-origin",
3839
"Content-Security-Policy": "default-src 'none'",
39-
"X-GitHub-Request-Id": "FBBC:4FD5:1C7963:325E5F:5E70A0EC"
40+
"X-GitHub-Request-Id": "B67A:2658:7E2214:85CE23:622267F4"
4041
}
4142
},
42-
"uuid": "d833590f-9896-462c-846b-712b50377536",
43+
"uuid": "ea1f3852-66f4-4238-b721-34f584b153dd",
4344
"persistent": true,
44-
"insertionIndex": 3
45+
"insertionIndex": 2
4546
}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.