Skip to content

Commit 995bee2

Browse files
authored
Merge branch 'main' into app_ids_for_checks
2 parents 6819f35 + 3043691 commit 995bee2

File tree

8 files changed

+334
-10
lines changed

8 files changed

+334
-10
lines changed

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

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,12 @@
22

33
import java.io.IOException;
44
import java.net.URL;
5-
import java.util.ArrayList;
6-
import java.util.Arrays;
7-
import java.util.Collection;
8-
import java.util.Collections;
9-
import java.util.List;
10-
import java.util.Map;
11-
import java.util.TreeMap;
5+
import java.util.*;
126

137
import static org.kohsuke.github.internal.Previews.INERTIA;
148

159
// TODO: Auto-generated Javadoc
10+
1611
/**
1712
* The type GHOrganization.
1813
*
@@ -240,6 +235,26 @@ public boolean hasMember(GHUser user) {
240235
}
241236
}
242237

238+
/**
239+
* Obtains the object that represents the user membership. In order to get a user's membership with an organization,
240+
* the authenticated user must be an organization member. The state parameter in the response can be used to
241+
* identify the user's membership status.
242+
*
243+
* @param username
244+
* the user's username
245+
* @return the GHMembership if the username belongs to the organisation, otherwise null
246+
* @throws IOException
247+
* the io exception
248+
*
249+
* @see <a href=
250+
* "https://docs.github.com/en/rest/orgs/members?apiVersion=2022-11-28#get-organization-membership-for-a-user">documentation</a>
251+
*/
252+
public GHMembership getMembership(String username) throws IOException {
253+
return root().createRequest()
254+
.withUrlPath("/orgs/" + login + "/memberships/" + username)
255+
.fetch(GHMembership.class);
256+
}
257+
243258
/**
244259
* Remove a member of the organisation - which will remove them from all teams, and remove their access to the
245260
* organization’s repositories.

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

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
import static org.junit.Assert.assertThrows;
1515

1616
// TODO: Auto-generated Javadoc
17+
1718
/**
1819
* The Class GHOrganizationTest.
1920
*/
@@ -242,6 +243,25 @@ public void testInviteUser() throws IOException {
242243
// assertTrue(org.hasMember(user));
243244
}
244245

246+
/**
247+
* Test get user membership
248+
*
249+
* @throws IOException
250+
* Signals that an I/O exception has occurred.
251+
*/
252+
@Test
253+
public void testGetMembership() throws IOException {
254+
GHOrganization org = gitHub.getOrganization("hub4j-test-org");
255+
256+
GHMembership membership = org.getMembership("fv316");
257+
258+
assertThat(membership, notNullValue());
259+
assertThat(membership.getRole(), equalTo(GHMembership.Role.ADMIN));
260+
assertThat(membership.getState(), equalTo(GHMembership.State.ACTIVE));
261+
assertThat(membership.getUser().getLogin(), equalTo("fv316"));
262+
assertThat(membership.getOrganization().login, equalTo("hub4j-test-org"));
263+
}
264+
245265
/**
246266
* Test list members with filter.
247267
*
@@ -375,7 +395,7 @@ public void testCreateTeamWithRepoAccess() throws IOException {
375395
GHRepository repo = org.getRepository(REPO_NAME);
376396

377397
// Create team with access to repository. Check access was granted.
378-
GHTeam team = org.createTeam(TEAM_NAME_CREATE, GHOrganization.Permission.PUSH, repo);
398+
GHTeam team = org.createTeam(TEAM_NAME_CREATE, Permission.PUSH, repo);
379399
assertThat(team.getRepositories().containsKey(REPO_NAME), is(true));
380400
assertThat(team.getPermission(), equalTo(Permission.PUSH.toString().toLowerCase()));
381401
}
@@ -424,7 +444,7 @@ public void testCreateTeamWithRepoPerm() throws Exception {
424444
// Create team with access to repository. Check access was granted.
425445
GHTeam team = org.createTeam(TEAM_NAME_CREATE).create();
426446

427-
team.add(repo, GHOrganization.Permission.PUSH);
447+
team.add(repo, Permission.PUSH);
428448

429449
assertThat(
430450
repo.getTeams()
@@ -453,7 +473,7 @@ public void testCreateTeamWithRepoRole() throws IOException {
453473
// Create team with access to repository. Check access was granted.
454474
GHTeam team = org.createTeam(TEAM_NAME_CREATE).create();
455475

456-
RepositoryRole role = RepositoryRole.from(GHOrganization.Permission.TRIAGE);
476+
RepositoryRole role = RepositoryRole.from(Permission.TRIAGE);
457477
team.add(repo, role);
458478

459479
// 'getPermission' does not return triage even though the UI shows that value
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
{
2+
"login": "fv316",
3+
"id": 34072742,
4+
"node_id": "MDQ6VXNlcjM0MDcyNzQy",
5+
"avatar_url": "https://avatars.githubusercontent.com/u/34072742?v=4",
6+
"gravatar_id": "",
7+
"url": "https://api.github.com/users/fv316",
8+
"html_url": "https://github.com/fv316",
9+
"followers_url": "https://api.github.com/users/fv316/followers",
10+
"following_url": "https://api.github.com/users/fv316/following{/other_user}",
11+
"gists_url": "https://api.github.com/users/fv316/gists{/gist_id}",
12+
"starred_url": "https://api.github.com/users/fv316/starred{/owner}{/repo}",
13+
"subscriptions_url": "https://api.github.com/users/fv316/subscriptions",
14+
"organizations_url": "https://api.github.com/users/fv316/orgs",
15+
"repos_url": "https://api.github.com/users/fv316/repos",
16+
"events_url": "https://api.github.com/users/fv316/events{/privacy}",
17+
"received_events_url": "https://api.github.com/users/fv316/received_events",
18+
"type": "User",
19+
"site_admin": false,
20+
"name": "Francisco Correia",
21+
"company": "Teya",
22+
"blog": "",
23+
"location": "Lisbon/ London",
24+
"email": null,
25+
"hireable": null,
26+
"bio": "Software developer at Teya. Electrical Engineer @ Imperial College. Data scientist @ École Polytechnique",
27+
"twitter_username": null,
28+
"public_repos": 29,
29+
"public_gists": 0,
30+
"followers": 6,
31+
"following": 5,
32+
"created_at": "2017-11-28T18:40:02Z",
33+
"updated_at": "2024-06-10T08:34:28Z"
34+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
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://avatars.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": "hub4jtestorgemail@could.be.null.com",
19+
"twitter_username": null,
20+
"is_verified": false,
21+
"has_organization_projects": true,
22+
"has_repository_projects": true,
23+
"public_repos": 27,
24+
"public_gists": 0,
25+
"followers": 2,
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+
"archived_at": null,
31+
"type": "Organization",
32+
"total_private_repos": 6,
33+
"owned_private_repos": 6,
34+
"private_gists": 0,
35+
"disk_usage": 12014,
36+
"collaborators": 1,
37+
"billing_email": "kk@kohsuke.org",
38+
"default_repository_permission": "none",
39+
"members_can_create_repositories": false,
40+
"two_factor_requirement_enabled": false,
41+
"members_allowed_repository_creation_type": "none",
42+
"members_can_create_public_repositories": false,
43+
"members_can_create_private_repositories": false,
44+
"members_can_create_internal_repositories": false,
45+
"members_can_create_pages": true,
46+
"members_can_fork_private_repositories": false,
47+
"web_commit_signoff_required": false,
48+
"members_can_create_public_pages": true,
49+
"members_can_create_private_pages": true,
50+
"plan": {
51+
"name": "free",
52+
"space": 976562499,
53+
"private_repos": 10000,
54+
"filled_seats": 52,
55+
"seats": 3
56+
},
57+
"advanced_security_enabled_for_new_repositories": false,
58+
"dependabot_alerts_enabled_for_new_repositories": false,
59+
"dependabot_security_updates_enabled_for_new_repositories": false,
60+
"dependency_graph_enabled_for_new_repositories": false,
61+
"secret_scanning_enabled_for_new_repositories": false,
62+
"secret_scanning_push_protection_enabled_for_new_repositories": false,
63+
"secret_scanning_push_protection_custom_link_enabled": false,
64+
"secret_scanning_push_protection_custom_link": null,
65+
"secret_scanning_validity_checks_enabled": false
66+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
{
2+
"url": "https://api.github.com/orgs/hub4j-test-org/memberships/fv316",
3+
"state": "active",
4+
"role": "admin",
5+
"organization_url": "https://api.github.com/orgs/hub4j-test-org",
6+
"user": {
7+
"login": "fv316",
8+
"id": 34072742,
9+
"node_id": "MDQ6VXNlcjM0MDcyNzQy",
10+
"avatar_url": "https://avatars.githubusercontent.com/u/34072742?v=4",
11+
"gravatar_id": "",
12+
"url": "https://api.github.com/users/fv316",
13+
"html_url": "https://github.com/fv316",
14+
"followers_url": "https://api.github.com/users/fv316/followers",
15+
"following_url": "https://api.github.com/users/fv316/following{/other_user}",
16+
"gists_url": "https://api.github.com/users/fv316/gists{/gist_id}",
17+
"starred_url": "https://api.github.com/users/fv316/starred{/owner}{/repo}",
18+
"subscriptions_url": "https://api.github.com/users/fv316/subscriptions",
19+
"organizations_url": "https://api.github.com/users/fv316/orgs",
20+
"repos_url": "https://api.github.com/users/fv316/repos",
21+
"events_url": "https://api.github.com/users/fv316/events{/privacy}",
22+
"received_events_url": "https://api.github.com/users/fv316/received_events",
23+
"type": "User",
24+
"site_admin": false
25+
},
26+
"organization": {
27+
"login": "hub4j-test-org",
28+
"id": 7544739,
29+
"node_id": "MDEyOk9yZ2FuaXphdGlvbjc1NDQ3Mzk=",
30+
"url": "https://api.github.com/orgs/hub4j-test-org",
31+
"repos_url": "https://api.github.com/orgs/hub4j-test-org/repos",
32+
"events_url": "https://api.github.com/orgs/hub4j-test-org/events",
33+
"hooks_url": "https://api.github.com/orgs/hub4j-test-org/hooks",
34+
"issues_url": "https://api.github.com/orgs/hub4j-test-org/issues",
35+
"members_url": "https://api.github.com/orgs/hub4j-test-org/members{/member}",
36+
"public_members_url": "https://api.github.com/orgs/hub4j-test-org/public_members{/member}",
37+
"avatar_url": "https://avatars.githubusercontent.com/u/7544739?v=4",
38+
"description": "Hub4j Test Org Description (this could be null or blank too)"
39+
}
40+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
{
2+
"id": "78c86a2e-48b0-4b78-a9c8-c409b4cc58e3",
3+
"name": "user",
4+
"request": {
5+
"url": "/user",
6+
"method": "GET",
7+
"headers": {
8+
"Accept": {
9+
"equalTo": "application/vnd.github.v3+json"
10+
}
11+
}
12+
},
13+
"response": {
14+
"status": 200,
15+
"bodyFileName": "1-user.json",
16+
"headers": {
17+
"Server": "GitHub.com",
18+
"Date": "Mon, 10 Jun 2024 09:07:17 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/\"eeffd28da9e86bf9a8b2cf03b36620ad72f1bccfccd1a5ee0a51a95dab4e05e9\"",
26+
"Last-Modified": "Mon, 10 Jun 2024 08:34:28 GMT",
27+
"github-authentication-token-expiration": "2024-06-17 10:06:09 +0100",
28+
"X-GitHub-Media-Type": "github.v3; format=json",
29+
"x-accepted-github-permissions": "allows_permissionless_access=true",
30+
"x-github-api-version-selected": "2022-11-28",
31+
"X-RateLimit-Limit": "5000",
32+
"X-RateLimit-Remaining": "4982",
33+
"X-RateLimit-Reset": "1718013850",
34+
"X-RateLimit-Used": "18",
35+
"X-RateLimit-Resource": "core",
36+
"Access-Control-Expose-Headers": "ETag, Link, Location, Retry-After, X-GitHub-OTP, X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Used, X-RateLimit-Resource, X-RateLimit-Reset, X-OAuth-Scopes, X-Accepted-OAuth-Scopes, X-Poll-Interval, X-GitHub-Media-Type, X-GitHub-SSO, X-GitHub-Request-Id, Deprecation, Sunset",
37+
"Access-Control-Allow-Origin": "*",
38+
"Strict-Transport-Security": "max-age=31536000; includeSubdomains; preload",
39+
"X-Frame-Options": "deny",
40+
"X-Content-Type-Options": "nosniff",
41+
"X-XSS-Protection": "0",
42+
"Referrer-Policy": "origin-when-cross-origin, strict-origin-when-cross-origin",
43+
"Content-Security-Policy": "default-src 'none'",
44+
"X-GitHub-Request-Id": "914E:19FF74:39926C:39E38C:6666C245"
45+
}
46+
},
47+
"uuid": "78c86a2e-48b0-4b78-a9c8-c409b4cc58e3",
48+
"persistent": true,
49+
"insertionIndex": 1
50+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
{
2+
"id": "9f6e328b-67ee-4481-8bcc-8b33b990dbd2",
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": "2-orgs_hub4j-test-org.json",
16+
"headers": {
17+
"Server": "GitHub.com",
18+
"Date": "Mon, 10 Jun 2024 09:07:19 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/\"67969e1a2c33b92087f1e2d76d07a944a80920a84bf07593fff4ec8c8d00f612\"",
26+
"Last-Modified": "Thu, 04 Jun 2020 05:56:10 GMT",
27+
"github-authentication-token-expiration": "2024-06-17 10:06:09 +0100",
28+
"X-GitHub-Media-Type": "github.v3; format=json",
29+
"x-accepted-github-permissions": "allows_permissionless_access=true",
30+
"x-github-api-version-selected": "2022-11-28",
31+
"X-RateLimit-Limit": "5000",
32+
"X-RateLimit-Remaining": "4977",
33+
"X-RateLimit-Reset": "1718013850",
34+
"X-RateLimit-Used": "23",
35+
"X-RateLimit-Resource": "core",
36+
"Access-Control-Expose-Headers": "ETag, Link, Location, Retry-After, X-GitHub-OTP, X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Used, X-RateLimit-Resource, X-RateLimit-Reset, X-OAuth-Scopes, X-Accepted-OAuth-Scopes, X-Poll-Interval, X-GitHub-Media-Type, X-GitHub-SSO, X-GitHub-Request-Id, Deprecation, Sunset",
37+
"Access-Control-Allow-Origin": "*",
38+
"Strict-Transport-Security": "max-age=31536000; includeSubdomains; preload",
39+
"X-Frame-Options": "deny",
40+
"X-Content-Type-Options": "nosniff",
41+
"X-XSS-Protection": "0",
42+
"Referrer-Policy": "origin-when-cross-origin, strict-origin-when-cross-origin",
43+
"Content-Security-Policy": "default-src 'none'",
44+
"X-GitHub-Request-Id": "56D5:19B6F6:69C4020:6A85446:6666C247"
45+
}
46+
},
47+
"uuid": "9f6e328b-67ee-4481-8bcc-8b33b990dbd2",
48+
"persistent": true,
49+
"insertionIndex": 2
50+
}

0 commit comments

Comments
 (0)