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 102e114

Browse filesBrowse files
feat: Get an external group in an organization
1 parent 7c204fe commit 102e114
Copy full SHA for 102e114

File tree

Expand file treeCollapse file tree

11 files changed

+370
-1
lines changed
Filter options
Expand file treeCollapse file tree

11 files changed

+370
-1
lines changed

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

Copy file name to clipboardExpand all lines: src/main/java/org/kohsuke/github/GHExternalGroup.java
+2-1Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,8 +173,9 @@ public String getEmail() {
173173
* @param owner
174174
* the owner
175175
*/
176-
void wrapUp(final GHOrganization owner) {
176+
GHExternalGroup wrapUp(final GHOrganization owner) {
177177
this.organization = owner;
178+
return this;
178179
}
179180

180181
/**

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

Copy file name to clipboardExpand all lines: src/main/java/org/kohsuke/github/GHOrganization.java
+24Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,30 @@ public PagedIterable<GHExternalGroup> listExternalGroups(final String displayNam
221221
return new GHExternalGroupsIterable(this, requester);
222222
}
223223

224+
/**
225+
* Gets a single external group by ID.
226+
*
227+
* @param groupId
228+
* id of the external group that we want to query for
229+
* @return the external group
230+
* @throws IOException
231+
* the io exception
232+
* @see <a href=
233+
* "https://docs.github.com/en/enterprise-cloud@latest/rest/teams/external-groups?apiVersion=2022-11-28#get-an-external-group">documentation</a>
234+
*/
235+
public GHExternalGroup getExternalGroup(final long groupId) throws IOException {
236+
try {
237+
return root().createRequest()
238+
.withUrlPath(String.format("/orgs/%s/external-group/%d", login, groupId))
239+
.fetch(GHExternalGroup.class)
240+
.wrapUp(this);
241+
} catch (final HttpException e) {
242+
throw EnterpriseManagedSupport.forOrganization(this)
243+
.handleException(e, "Could not retrieve organization external group")
244+
.orElse(e);
245+
}
246+
}
247+
224248
/**
225249
* Member's role in an organization.
226250
*/

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

Copy file name to clipboardExpand all lines: src/test/java/org/kohsuke/github/GHOrganizationTest.java
+43Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -694,4 +694,47 @@ public void testListExternalGroupsNotEnterpriseManagedOrganization() throws IOEx
694694
assertThat(error.getDocumentationUrl(), notNullValue());
695695
}
696696

697+
/**
698+
* Test get external group
699+
*
700+
* @throws IOException
701+
* Signals that an I/O exception has occurred.
702+
*/
703+
@Test
704+
public void testGetExternalGroup() throws IOException {
705+
GHOrganization org = gitHub.getOrganization(GITHUB_API_TEST_ORG);
706+
707+
GHExternalGroup group = org.getExternalGroup(467431L);
708+
709+
assertThat(group, not(isExternalGroupSummary()));
710+
711+
assertThat(group.getId(), equalTo(467431L));
712+
assertThat(group.getName(), equalTo("acme-developers"));
713+
assertThat(group.getUpdatedAt(), notNullValue());
714+
715+
assertThat(group.getMembers(), notNullValue());
716+
assertThat(membersSummary(group),
717+
hasItems("158311279:john-doe_acme:John Doe:john.doe@acme.corp",
718+
"166731041:jane-doe_acme:Jane Doe:jane.doe@acme.corp"));
719+
720+
assertThat(group.getTeams(), notNullValue());
721+
assertThat(teamSummary(group), hasItems("9891173:ACME-DEVELOPERS"));
722+
}
723+
724+
/**
725+
* Test get external group for not enterprise managed organization
726+
*
727+
* @throws IOException
728+
* Signals that an I/O exception has occurred.
729+
*/
730+
@Test
731+
public void testGetExternalGroupNotEnterpriseManagedOrganization() throws IOException {
732+
GHOrganization org = gitHub.getOrganization(GITHUB_API_TEST_ORG);
733+
734+
final GHIOException failure = assertThrows(GHNotExternallyManagedEnterpriseException.class,
735+
() -> org.getExternalGroup(12345));
736+
737+
assertThat(failure.getMessage(), equalTo("Could not retrieve organization external group"));
738+
}
739+
697740
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
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://avatars3.githubusercontent.com/u/7544739?v=4",
13+
"description": null,
14+
"is_verified": false,
15+
"has_organization_projects": true,
16+
"has_repository_projects": true,
17+
"public_repos": 11,
18+
"public_gists": 0,
19+
"followers": 0,
20+
"following": 0,
21+
"html_url": "https://github.com/hub4j-test-org",
22+
"created_at": "2014-05-10T19:39:11Z",
23+
"updated_at": "2015-04-20T00:42:30Z",
24+
"type": "Organization",
25+
"total_private_repos": 0,
26+
"owned_private_repos": 0,
27+
"private_gists": 0,
28+
"disk_usage": 147,
29+
"collaborators": 0,
30+
"billing_email": "kk@kohsuke.org",
31+
"default_repository_permission": "none",
32+
"members_can_create_repositories": false,
33+
"two_factor_requirement_enabled": false,
34+
"plan": {
35+
"name": "free",
36+
"space": 976562499,
37+
"private_repos": 0,
38+
"filled_seats": 12,
39+
"seats": 0
40+
}
41+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
{
2+
"group_id": 467431,
3+
"group_name": "acme-developers",
4+
"updated_at": "2023-09-13T16:41:28Z",
5+
"members": [
6+
{
7+
"member_id": 158311279,
8+
"member_login": "john-doe_acme",
9+
"member_name": "John Doe",
10+
"member_email": "john.doe@acme.corp"
11+
},
12+
{
13+
"member_id": 166731041,
14+
"member_login": "jane-doe_acme",
15+
"member_name": "Jane Doe",
16+
"member_email": "jane.doe@acme.corp"
17+
}
18+
],
19+
"teams": [
20+
{
21+
"team_id": 9891173,
22+
"team_name": "ACME-DEVELOPERS"
23+
}
24+
]
25+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
{
2+
"id": "3ed48345-73c2-4d8e-9c65-f4a140356d59",
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": "1-orgs_hub4j-test-org.json",
16+
"headers": {
17+
"Server": "GitHub.com",
18+
"Date": "Tue, 25 Feb 2020 14:41:05 GMT",
19+
"Content-Type": "application/json; charset=utf-8",
20+
"Status": "200 OK",
21+
"X-RateLimit-Limit": "5000",
22+
"X-RateLimit-Remaining": "4984",
23+
"X-RateLimit-Reset": "1582644474",
24+
"Cache-Control": "private, max-age=60, s-maxage=60",
25+
"Vary": [
26+
"Accept, Authorization, Cookie, X-GitHub-OTP",
27+
"Accept-Encoding, Accept, X-Requested-With"
28+
],
29+
"ETag": "W/\"712644daa44df3089a27d6ef60979929\"",
30+
"Last-Modified": "Mon, 20 Apr 2015 00:42:30 GMT",
31+
"X-OAuth-Scopes": "delete_repo, repo, user",
32+
"X-Accepted-OAuth-Scopes": "admin:org, read:org, repo, user, write:org",
33+
"X-GitHub-Media-Type": "unknown, github.v3",
34+
"Access-Control-Expose-Headers": "ETag, Link, Location, Retry-After, X-GitHub-OTP, X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Reset, X-OAuth-Scopes, X-Accepted-OAuth-Scopes, X-Poll-Interval, X-GitHub-Media-Type",
35+
"Access-Control-Allow-Origin": "*",
36+
"Strict-Transport-Security": "max-age=31536000; includeSubdomains; preload",
37+
"X-Frame-Options": "deny",
38+
"X-Content-Type-Options": "nosniff",
39+
"X-XSS-Protection": "1; mode=block",
40+
"Referrer-Policy": "origin-when-cross-origin, strict-origin-when-cross-origin",
41+
"Content-Security-Policy": "default-src 'none'",
42+
"X-GitHub-Request-Id": "EB37:2979:3EAF7E:786110:5E5531FF"
43+
}
44+
},
45+
"uuid": "3ed48345-73c2-4d8e-9c65-f4a140356d59",
46+
"persistent": true,
47+
"insertionIndex": 1
48+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
{
2+
"id": "ef9f50f7-160c-4410-a82e-68d3e14fb250",
3+
"name": "orgs_hub4j-test-org_external-group_467431",
4+
"request": {
5+
"url": "/orgs/hub4j-test-org/external-group/467431",
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-o_h_external-group_467431.json",
16+
"headers": {
17+
"Server": "GitHub.com",
18+
"Date": "Tue, 25 Feb 2020 14:41:06 GMT",
19+
"Content-Type": "application/json; charset=utf-8",
20+
"Status": "200 OK",
21+
"X-RateLimit-Limit": "5000",
22+
"X-RateLimit-Remaining": "4983",
23+
"X-RateLimit-Reset": "1582644475",
24+
"Cache-Control": "private, max-age=60, s-maxage=60",
25+
"Vary": [
26+
"Accept, Authorization, Cookie, X-GitHub-OTP",
27+
"Accept-Encoding, Accept, X-Requested-With"
28+
],
29+
"ETag": "W/\"631de12e6bc586863218257765331a70\"",
30+
"X-OAuth-Scopes": "delete_repo, repo, user",
31+
"X-Accepted-OAuth-Scopes": "",
32+
"X-GitHub-Media-Type": "unknown, github.v3",
33+
"Access-Control-Expose-Headers": "ETag, Link, Location, Retry-After, X-GitHub-OTP, X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Reset, X-OAuth-Scopes, X-Accepted-OAuth-Scopes, X-Poll-Interval, X-GitHub-Media-Type",
34+
"Access-Control-Allow-Origin": "*",
35+
"Strict-Transport-Security": "max-age=31536000; includeSubdomains; preload",
36+
"X-Frame-Options": "deny",
37+
"X-Content-Type-Options": "nosniff",
38+
"X-XSS-Protection": "1; mode=block",
39+
"Referrer-Policy": "origin-when-cross-origin, strict-origin-when-cross-origin",
40+
"Content-Security-Policy": "default-src 'none'",
41+
"X-GitHub-Request-Id": "EB37:2979:3EAF8C:78624D:5E553201"
42+
}
43+
},
44+
"uuid": "ef9f50f7-160c-4410-a82e-68d3e14fb250",
45+
"persistent": true,
46+
"insertionIndex": 2
47+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
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://avatars3.githubusercontent.com/u/7544739?v=4",
13+
"description": null,
14+
"is_verified": false,
15+
"has_organization_projects": true,
16+
"has_repository_projects": true,
17+
"public_repos": 11,
18+
"public_gists": 0,
19+
"followers": 0,
20+
"following": 0,
21+
"html_url": "https://github.com/hub4j-test-org",
22+
"created_at": "2014-05-10T19:39:11Z",
23+
"updated_at": "2015-04-20T00:42:30Z",
24+
"type": "Organization",
25+
"total_private_repos": 0,
26+
"owned_private_repos": 0,
27+
"private_gists": 0,
28+
"disk_usage": 147,
29+
"collaborators": 0,
30+
"billing_email": "kk@kohsuke.org",
31+
"default_repository_permission": "none",
32+
"members_can_create_repositories": false,
33+
"two_factor_requirement_enabled": false,
34+
"plan": {
35+
"name": "free",
36+
"space": 976562499,
37+
"private_repos": 0,
38+
"filled_seats": 12,
39+
"seats": 0
40+
}
41+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"message": "This organization is not part of externally managed enterprise.",
3+
"documentation_url": "https://docs.github.com/rest/teams/external-groups#list-external-groups-in-an-organization"
4+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
{
2+
"id": "3ed48345-73c2-4d8e-9c65-f4a140356d59",
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": "1-orgs_hub4j-test-org.json",
16+
"headers": {
17+
"Server": "GitHub.com",
18+
"Date": "Tue, 25 Feb 2020 14:41:05 GMT",
19+
"Content-Type": "application/json; charset=utf-8",
20+
"Status": "200 OK",
21+
"X-RateLimit-Limit": "5000",
22+
"X-RateLimit-Remaining": "4984",
23+
"X-RateLimit-Reset": "1582644474",
24+
"Cache-Control": "private, max-age=60, s-maxage=60",
25+
"Vary": [
26+
"Accept, Authorization, Cookie, X-GitHub-OTP",
27+
"Accept-Encoding, Accept, X-Requested-With"
28+
],
29+
"ETag": "W/\"712644daa44df3089a27d6ef60979929\"",
30+
"Last-Modified": "Mon, 20 Apr 2015 00:42:30 GMT",
31+
"X-OAuth-Scopes": "delete_repo, repo, user",
32+
"X-Accepted-OAuth-Scopes": "admin:org, read:org, repo, user, write:org",
33+
"X-GitHub-Media-Type": "unknown, github.v3",
34+
"Access-Control-Expose-Headers": "ETag, Link, Location, Retry-After, X-GitHub-OTP, X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Reset, X-OAuth-Scopes, X-Accepted-OAuth-Scopes, X-Poll-Interval, X-GitHub-Media-Type",
35+
"Access-Control-Allow-Origin": "*",
36+
"Strict-Transport-Security": "max-age=31536000; includeSubdomains; preload",
37+
"X-Frame-Options": "deny",
38+
"X-Content-Type-Options": "nosniff",
39+
"X-XSS-Protection": "1; mode=block",
40+
"Referrer-Policy": "origin-when-cross-origin, strict-origin-when-cross-origin",
41+
"Content-Security-Policy": "default-src 'none'",
42+
"X-GitHub-Request-Id": "EB37:2979:3EAF7E:786110:5E5531FF"
43+
}
44+
},
45+
"uuid": "3ed48345-73c2-4d8e-9c65-f4a140356d59",
46+
"persistent": true,
47+
"insertionIndex": 1
48+
}

0 commit comments

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