Skip to content

Commit 5d3344a

Browse files
authored
Merge pull request #2015 from anujhydrabadi/bug/ghperson-type
GHPerson#getType() should call populate() only if type is null
2 parents e7e0343 + 7201986 commit 5d3344a

File tree

9 files changed

+254
-1
lines changed

9 files changed

+254
-1
lines changed

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -316,7 +316,9 @@ public int getFollowersCount() throws IOException {
316316
* the io exception
317317
*/
318318
public String getType() throws IOException {
319-
populate();
319+
if (type == null) {
320+
populate();
321+
}
320322
return type;
321323
}
322324

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ public void getGitHubApp() throws IOException {
5757
assertThat(app.getId(), is((long) 82994));
5858
assertThat(app.getOwner().getId(), is((long) 7544739));
5959
assertThat(app.getOwner().getLogin(), is("hub4j-test-org"));
60+
assertThat(app.getOwner().getType(), is("Organization"));
6061
assertThat(app.getName(), is("GHApi Test app 1"));
6162
assertThat(app.getSlug(), is("ghapi-test-app-1"));
6263
assertThat(app.getDescription(), is(""));
@@ -85,8 +86,10 @@ public void listInstallationRequests() throws IOException {
8586
assertThat(appInstallation.getId(), is((long) 1037204));
8687
assertThat(appInstallation.getAccount().getId(), is((long) 195438329));
8788
assertThat(appInstallation.getAccount().getLogin(), is("approval-test"));
89+
assertThat(appInstallation.getAccount().getType(), is("Organization"));
8890
assertThat(appInstallation.getRequester().getId(), is((long) 195437694));
8991
assertThat(appInstallation.getRequester().getLogin(), is("kaladinstormblessed2"));
92+
assertThat(appInstallation.getRequester().getType(), is("User"));
9093
assertThat(appInstallation.getCreatedAt(), is(GitHubClient.parseDate("2025-01-17T15:50:51Z")));
9194
assertThat(appInstallation.getNodeId(), is("MDMwOkludGVncmF0aW9uSW5zdGFsbGF0aW9uUmVxdWVzdDEwMzcyMDQ="));
9295
}
@@ -275,6 +278,7 @@ private void testAppInstallation(GHAppInstallation appInstallation) throws IOExc
275278
assertThat(appInstallation.getId(), is((long) 11111111));
276279
assertThat(appAccount.getId(), is((long) 111111111));
277280
assertThat(appAccount.login, is("bogus"));
281+
assertThat(appAccount.getType(), is("Organization"));
278282
assertThat(appInstallation.getRepositorySelection(), is(GHRepositorySelection.SELECTED));
279283
assertThat(appInstallation.getAccessTokenUrl(), endsWith("/app/installations/11111111/access_tokens"));
280284
assertThat(appInstallation.getRepositoriesUrl(), endsWith("/installation/repositories"));

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

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,22 @@ public void getOrgs() throws IOException {
9696
assertThat(org, not(sameInstance(org2)));
9797
}
9898

99+
/**
100+
* Verifies that the `type` field is correctly fetched when listing organizations.
101+
* <p>
102+
* Since the `type` field is not included by default in the list of organizations, this test ensures that calling
103+
* {@code getType()} retrieves the expected value.
104+
* </p>
105+
*
106+
* @throws IOException
107+
* if an I/O error occurs while fetching the organizations.
108+
*/
109+
@Test
110+
public void listOrganizationsFetchesType() throws IOException {
111+
String type = gitHub.listOrganizations().withPageSize(1).iterator().next().getType();
112+
assertThat(type, equalTo("Organization"));
113+
}
114+
99115
/**
100116
* Search users.
101117
*
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
{
2+
"login": "anujhydrabadi",
3+
"id": 129152617,
4+
"node_id": "U_kgDOB7K2aQ",
5+
"avatar_url": "https://avatars.githubusercontent.com/u/129152617?v=4",
6+
"gravatar_id": "",
7+
"url": "https://api.github.com/users/anujhydrabadi",
8+
"html_url": "https://github.com/anujhydrabadi",
9+
"followers_url": "https://api.github.com/users/anujhydrabadi/followers",
10+
"following_url": "https://api.github.com/users/anujhydrabadi/following{/other_user}",
11+
"gists_url": "https://api.github.com/users/anujhydrabadi/gists{/gist_id}",
12+
"starred_url": "https://api.github.com/users/anujhydrabadi/starred{/owner}{/repo}",
13+
"subscriptions_url": "https://api.github.com/users/anujhydrabadi/subscriptions",
14+
"organizations_url": "https://api.github.com/users/anujhydrabadi/orgs",
15+
"repos_url": "https://api.github.com/users/anujhydrabadi/repos",
16+
"events_url": "https://api.github.com/users/anujhydrabadi/events{/privacy}",
17+
"received_events_url": "https://api.github.com/users/anujhydrabadi/received_events",
18+
"type": "User",
19+
"user_view_type": "private",
20+
"site_admin": false,
21+
"name": "Anuj Hydrabadi",
22+
"company": "@Facets-cloud",
23+
"blog": "",
24+
"location": null,
25+
"email": null,
26+
"hireable": null,
27+
"bio": null,
28+
"twitter_username": null,
29+
"notification_email": null,
30+
"public_repos": 6,
31+
"public_gists": 1,
32+
"followers": 0,
33+
"following": 0,
34+
"created_at": "2023-03-28T07:02:48Z",
35+
"updated_at": "2025-01-31T11:08:30Z",
36+
"private_gists": 0,
37+
"total_private_repos": 28,
38+
"owned_private_repos": 28,
39+
"disk_usage": 1269,
40+
"collaborators": 2,
41+
"two_factor_authentication": true,
42+
"plan": {
43+
"name": "free",
44+
"space": 976562499,
45+
"collaborators": 0,
46+
"private_repos": 10000
47+
}
48+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
[
2+
{
3+
"login": "errfree",
4+
"id": 44,
5+
"node_id": "MDEyOk9yZ2FuaXphdGlvbjQ0",
6+
"url": "https://api.github.com/orgs/errfree",
7+
"repos_url": "https://api.github.com/orgs/errfree/repos",
8+
"events_url": "https://api.github.com/orgs/errfree/events",
9+
"hooks_url": "https://api.github.com/orgs/errfree/hooks",
10+
"issues_url": "https://api.github.com/orgs/errfree/issues",
11+
"members_url": "https://api.github.com/orgs/errfree/members{/member}",
12+
"public_members_url": "https://api.github.com/orgs/errfree/public_members{/member}",
13+
"avatar_url": "https://avatars.githubusercontent.com/u/44?v=4",
14+
"description": null
15+
}
16+
]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
{
2+
"login": "errfree",
3+
"id": 44,
4+
"node_id": "MDEyOk9yZ2FuaXphdGlvbjQ0",
5+
"url": "https://api.github.com/orgs/errfree",
6+
"repos_url": "https://api.github.com/orgs/errfree/repos",
7+
"events_url": "https://api.github.com/orgs/errfree/events",
8+
"hooks_url": "https://api.github.com/orgs/errfree/hooks",
9+
"issues_url": "https://api.github.com/orgs/errfree/issues",
10+
"members_url": "https://api.github.com/orgs/errfree/members{/member}",
11+
"public_members_url": "https://api.github.com/orgs/errfree/public_members{/member}",
12+
"avatar_url": "https://avatars.githubusercontent.com/u/44?v=4",
13+
"description": null,
14+
"is_verified": false,
15+
"has_organization_projects": true,
16+
"has_repository_projects": true,
17+
"public_repos": 2,
18+
"public_gists": 0,
19+
"followers": 14,
20+
"following": 0,
21+
"html_url": "https://github.com/errfree",
22+
"created_at": "2008-01-24T02:08:37Z",
23+
"updated_at": "2020-05-13T06:35:19Z",
24+
"archived_at": null,
25+
"type": "Organization"
26+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
{
2+
"id": "cd7530db-bd05-4525-9136-0bf80e609c23",
3+
"name": "user",
4+
"request": {
5+
"url": "/user",
6+
"method": "GET",
7+
"headers": {
8+
"Accept": {
9+
"equalTo": "application/vnd.github+json"
10+
}
11+
}
12+
},
13+
"response": {
14+
"status": 200,
15+
"bodyFileName": "1-user.json",
16+
"headers": {
17+
"Date": "Sun, 16 Feb 2025 09:01:24 GMT",
18+
"Content-Type": "application/json; charset=utf-8",
19+
"Cache-Control": "private, max-age=60, s-maxage=60",
20+
"Vary": "Accept, Authorization, Cookie, X-GitHub-OTP,Accept-Encoding, Accept, X-Requested-With",
21+
"ETag": "W/\"2288274ffc402f5864177c99f29e71d41d774342ce2b6fc9d2b12db0df22c6ef\"",
22+
"Last-Modified": "Fri, 31 Jan 2025 11:08:30 GMT",
23+
"X-OAuth-Scopes": "admin:enterprise, admin:gpg_key, admin:org, admin:org_hook, admin:public_key, admin:repo_hook, admin:ssh_signing_key, audit_log, codespace, delete:packages, delete_repo, gist, notifications, project, repo, user, workflow, write:discussion, write:packages",
24+
"X-Accepted-OAuth-Scopes": "",
25+
"X-GitHub-Media-Type": "github.v3; format=json",
26+
"x-github-api-version-selected": "2022-11-28",
27+
"X-RateLimit-Limit": "5000",
28+
"X-RateLimit-Remaining": "4962",
29+
"X-RateLimit-Reset": "1739697044",
30+
"X-RateLimit-Used": "38",
31+
"X-RateLimit-Resource": "core",
32+
"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",
33+
"Access-Control-Allow-Origin": "*",
34+
"Strict-Transport-Security": "max-age=31536000; includeSubdomains; preload",
35+
"X-Frame-Options": "deny",
36+
"X-Content-Type-Options": "nosniff",
37+
"X-XSS-Protection": "0",
38+
"Referrer-Policy": "origin-when-cross-origin, strict-origin-when-cross-origin",
39+
"Content-Security-Policy": "default-src 'none'",
40+
"Server": "github.com",
41+
"X-GitHub-Request-Id": "415A:2933E2:783482:ABFF69:67B1A964"
42+
}
43+
},
44+
"uuid": "cd7530db-bd05-4525-9136-0bf80e609c23",
45+
"persistent": true,
46+
"insertionIndex": 1
47+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
{
2+
"id": "87f5d76b-1169-4caf-ab76-04ac6b1e78b9",
3+
"name": "organizations",
4+
"request": {
5+
"url": "/organizations?per_page=1",
6+
"method": "GET",
7+
"headers": {
8+
"Accept": {
9+
"equalTo": "application/vnd.github+json"
10+
}
11+
}
12+
},
13+
"response": {
14+
"status": 200,
15+
"bodyFileName": "2-organizations.json",
16+
"headers": {
17+
"Date": "Sun, 16 Feb 2025 09:01:25 GMT",
18+
"Content-Type": "application/json; charset=utf-8",
19+
"Cache-Control": "private, max-age=60, s-maxage=60",
20+
"Vary": "Accept, Authorization, Cookie, X-GitHub-OTP,Accept-Encoding, Accept, X-Requested-With",
21+
"ETag": "W/\"575d7c16fc728d88180cb71aecfb2c215cdf28f0259a6eac1d93c607816f3722\"",
22+
"X-OAuth-Scopes": "admin:enterprise, admin:gpg_key, admin:org, admin:org_hook, admin:public_key, admin:repo_hook, admin:ssh_signing_key, audit_log, codespace, delete:packages, delete_repo, gist, notifications, project, repo, user, workflow, write:discussion, write:packages",
23+
"X-Accepted-OAuth-Scopes": "",
24+
"X-GitHub-Media-Type": "github.v3; format=json",
25+
"x-github-api-version-selected": "2022-11-28",
26+
"X-RateLimit-Limit": "5000",
27+
"X-RateLimit-Remaining": "4960",
28+
"X-RateLimit-Reset": "1739697044",
29+
"X-RateLimit-Used": "40",
30+
"X-RateLimit-Resource": "core",
31+
"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",
32+
"Access-Control-Allow-Origin": "*",
33+
"Strict-Transport-Security": "max-age=31536000; includeSubdomains; preload",
34+
"X-Frame-Options": "deny",
35+
"X-Content-Type-Options": "nosniff",
36+
"X-XSS-Protection": "0",
37+
"Referrer-Policy": "origin-when-cross-origin, strict-origin-when-cross-origin",
38+
"Content-Security-Policy": "default-src 'none'",
39+
"Server": "github.com",
40+
"X-GitHub-Request-Id": "58BE:2FA953:5F36F5:9301D2:67B1A965",
41+
"Link": "<https://api.github.com/organizations?per_page=1&since=44>; rel=\"next\", <https://api.github.com/organizations{?since}>; rel=\"first\""
42+
}
43+
},
44+
"uuid": "87f5d76b-1169-4caf-ab76-04ac6b1e78b9",
45+
"persistent": true,
46+
"insertionIndex": 2
47+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
{
2+
"id": "950bf65f-6dda-43d1-9ded-907e269024df",
3+
"name": "orgs_errfree",
4+
"request": {
5+
"url": "/orgs/errfree",
6+
"method": "GET",
7+
"headers": {
8+
"Accept": {
9+
"equalTo": "application/vnd.github+json"
10+
}
11+
}
12+
},
13+
"response": {
14+
"status": 200,
15+
"bodyFileName": "3-orgs_errfree.json",
16+
"headers": {
17+
"Date": "Sun, 16 Feb 2025 09:01:25 GMT",
18+
"Content-Type": "application/json; charset=utf-8",
19+
"Cache-Control": "private, max-age=60, s-maxage=60",
20+
"Vary": "Accept, Authorization, Cookie, X-GitHub-OTP,Accept-Encoding, Accept, X-Requested-With",
21+
"ETag": "W/\"fdf38082b2dec2c4293a820e9f615c582c00ca7ab2365a5db1a7f7a3a1905dbd\"",
22+
"Last-Modified": "Wed, 13 May 2020 06:35:19 GMT",
23+
"X-OAuth-Scopes": "admin:enterprise, admin:gpg_key, admin:org, admin:org_hook, admin:public_key, admin:repo_hook, admin:ssh_signing_key, audit_log, codespace, delete:packages, delete_repo, gist, notifications, project, repo, user, workflow, write:discussion, write:packages",
24+
"X-Accepted-OAuth-Scopes": "admin:org, read:org, repo, user, write:org",
25+
"X-GitHub-Media-Type": "github.v3; format=json",
26+
"x-github-api-version-selected": "2022-11-28",
27+
"X-RateLimit-Limit": "5000",
28+
"X-RateLimit-Remaining": "4959",
29+
"X-RateLimit-Reset": "1739697044",
30+
"X-RateLimit-Used": "41",
31+
"X-RateLimit-Resource": "core",
32+
"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",
33+
"Access-Control-Allow-Origin": "*",
34+
"Strict-Transport-Security": "max-age=31536000; includeSubdomains; preload",
35+
"X-Frame-Options": "deny",
36+
"X-Content-Type-Options": "nosniff",
37+
"X-XSS-Protection": "0",
38+
"Referrer-Policy": "origin-when-cross-origin, strict-origin-when-cross-origin",
39+
"Content-Security-Policy": "default-src 'none'",
40+
"Server": "github.com",
41+
"X-GitHub-Request-Id": "1EF0:22ABA6:638768:974F6C:67B1A965"
42+
}
43+
},
44+
"uuid": "950bf65f-6dda-43d1-9ded-907e269024df",
45+
"persistent": true,
46+
"insertionIndex": 3
47+
}

0 commit comments

Comments
 (0)