Skip to content

GHPerson#getType() should call populate() only if type is null #2015

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Feb 25, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/main/java/org/kohsuke/github/GHPerson.java
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,9 @@ public int getFollowersCount() throws IOException {
* the io exception
*/
public String getType() throws IOException {
populate();
if (type == null) {
populate();
}
return type;
}

Expand Down
4 changes: 4 additions & 0 deletions src/test/java/org/kohsuke/github/GHAppTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ public void getGitHubApp() throws IOException {
assertThat(app.getId(), is((long) 82994));
assertThat(app.getOwner().getId(), is((long) 7544739));
assertThat(app.getOwner().getLogin(), is("hub4j-test-org"));
assertThat(app.getOwner().getType(), is("Organization"));
assertThat(app.getName(), is("GHApi Test app 1"));
assertThat(app.getSlug(), is("ghapi-test-app-1"));
assertThat(app.getDescription(), is(""));
Expand Down Expand Up @@ -85,8 +86,10 @@ public void listInstallationRequests() throws IOException {
assertThat(appInstallation.getId(), is((long) 1037204));
assertThat(appInstallation.getAccount().getId(), is((long) 195438329));
assertThat(appInstallation.getAccount().getLogin(), is("approval-test"));
assertThat(appInstallation.getAccount().getType(), is("Organization"));
assertThat(appInstallation.getRequester().getId(), is((long) 195437694));
assertThat(appInstallation.getRequester().getLogin(), is("kaladinstormblessed2"));
assertThat(appInstallation.getRequester().getType(), is("User"));
assertThat(appInstallation.getCreatedAt(), is(GitHubClient.parseDate("2025-01-17T15:50:51Z")));
assertThat(appInstallation.getNodeId(), is("MDMwOkludGVncmF0aW9uSW5zdGFsbGF0aW9uUmVxdWVzdDEwMzcyMDQ="));
}
Expand Down Expand Up @@ -275,6 +278,7 @@ private void testAppInstallation(GHAppInstallation appInstallation) throws IOExc
assertThat(appInstallation.getId(), is((long) 11111111));
assertThat(appAccount.getId(), is((long) 111111111));
assertThat(appAccount.login, is("bogus"));
assertThat(appAccount.getType(), is("Organization"));
assertThat(appInstallation.getRepositorySelection(), is(GHRepositorySelection.SELECTED));
assertThat(appInstallation.getAccessTokenUrl(), endsWith("/app/installations/11111111/access_tokens"));
assertThat(appInstallation.getRepositoriesUrl(), endsWith("/installation/repositories"));
Expand Down
16 changes: 16 additions & 0 deletions src/test/java/org/kohsuke/github/GitHubTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,22 @@ public void getOrgs() throws IOException {
assertThat(org, not(sameInstance(org2)));
}

/**
* Verifies that the `type` field is correctly fetched when listing organizations.
* <p>
* Since the `type` field is not included by default in the list of organizations, this test ensures that calling
* {@code getType()} retrieves the expected value.
* </p>
*
* @throws IOException
* if an I/O error occurs while fetching the organizations.
*/
@Test
public void listOrganizationsFetchesType() throws IOException {
String type = gitHub.listOrganizations().withPageSize(1).iterator().next().getType();
assertThat(type, equalTo("Organization"));
}

/**
* Search users.
*
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
{
"login": "anujhydrabadi",
"id": 129152617,
"node_id": "U_kgDOB7K2aQ",
"avatar_url": "https://avatars.githubusercontent.com/u/129152617?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/anujhydrabadi",
"html_url": "https://github.com/anujhydrabadi",
"followers_url": "https://api.github.com/users/anujhydrabadi/followers",
"following_url": "https://api.github.com/users/anujhydrabadi/following{/other_user}",
"gists_url": "https://api.github.com/users/anujhydrabadi/gists{/gist_id}",
"starred_url": "https://api.github.com/users/anujhydrabadi/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/anujhydrabadi/subscriptions",
"organizations_url": "https://api.github.com/users/anujhydrabadi/orgs",
"repos_url": "https://api.github.com/users/anujhydrabadi/repos",
"events_url": "https://api.github.com/users/anujhydrabadi/events{/privacy}",
"received_events_url": "https://api.github.com/users/anujhydrabadi/received_events",
"type": "User",
"user_view_type": "private",
"site_admin": false,
"name": "Anuj Hydrabadi",
"company": "@Facets-cloud",
"blog": "",
"location": null,
"email": null,
"hireable": null,
"bio": null,
"twitter_username": null,
"notification_email": null,
"public_repos": 6,
"public_gists": 1,
"followers": 0,
"following": 0,
"created_at": "2023-03-28T07:02:48Z",
"updated_at": "2025-01-31T11:08:30Z",
"private_gists": 0,
"total_private_repos": 28,
"owned_private_repos": 28,
"disk_usage": 1269,
"collaborators": 2,
"two_factor_authentication": true,
"plan": {
"name": "free",
"space": 976562499,
"collaborators": 0,
"private_repos": 10000
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
[
{
"login": "errfree",
"id": 44,
"node_id": "MDEyOk9yZ2FuaXphdGlvbjQ0",
"url": "https://api.github.com/orgs/errfree",
"repos_url": "https://api.github.com/orgs/errfree/repos",
"events_url": "https://api.github.com/orgs/errfree/events",
"hooks_url": "https://api.github.com/orgs/errfree/hooks",
"issues_url": "https://api.github.com/orgs/errfree/issues",
"members_url": "https://api.github.com/orgs/errfree/members{/member}",
"public_members_url": "https://api.github.com/orgs/errfree/public_members{/member}",
"avatar_url": "https://avatars.githubusercontent.com/u/44?v=4",
"description": null
}
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"login": "errfree",
"id": 44,
"node_id": "MDEyOk9yZ2FuaXphdGlvbjQ0",
"url": "https://api.github.com/orgs/errfree",
"repos_url": "https://api.github.com/orgs/errfree/repos",
"events_url": "https://api.github.com/orgs/errfree/events",
"hooks_url": "https://api.github.com/orgs/errfree/hooks",
"issues_url": "https://api.github.com/orgs/errfree/issues",
"members_url": "https://api.github.com/orgs/errfree/members{/member}",
"public_members_url": "https://api.github.com/orgs/errfree/public_members{/member}",
"avatar_url": "https://avatars.githubusercontent.com/u/44?v=4",
"description": null,
"is_verified": false,
"has_organization_projects": true,
"has_repository_projects": true,
"public_repos": 2,
"public_gists": 0,
"followers": 14,
"following": 0,
"html_url": "https://github.com/errfree",
"created_at": "2008-01-24T02:08:37Z",
"updated_at": "2020-05-13T06:35:19Z",
"archived_at": null,
"type": "Organization"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
{
"id": "cd7530db-bd05-4525-9136-0bf80e609c23",
"name": "user",
"request": {
"url": "/user",
"method": "GET",
"headers": {
"Accept": {
"equalTo": "application/vnd.github+json"
}
}
},
"response": {
"status": 200,
"bodyFileName": "1-user.json",
"headers": {
"Date": "Sun, 16 Feb 2025 09:01:24 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/\"2288274ffc402f5864177c99f29e71d41d774342ce2b6fc9d2b12db0df22c6ef\"",
"Last-Modified": "Fri, 31 Jan 2025 11:08:30 GMT",
"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",
"X-Accepted-OAuth-Scopes": "",
"X-GitHub-Media-Type": "github.v3; format=json",
"x-github-api-version-selected": "2022-11-28",
"X-RateLimit-Limit": "5000",
"X-RateLimit-Remaining": "4962",
"X-RateLimit-Reset": "1739697044",
"X-RateLimit-Used": "38",
"X-RateLimit-Resource": "core",
"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",
"Access-Control-Allow-Origin": "*",
"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'",
"Server": "github.com",
"X-GitHub-Request-Id": "415A:2933E2:783482:ABFF69:67B1A964"
}
},
"uuid": "cd7530db-bd05-4525-9136-0bf80e609c23",
"persistent": true,
"insertionIndex": 1
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
{
"id": "87f5d76b-1169-4caf-ab76-04ac6b1e78b9",
"name": "organizations",
"request": {
"url": "/organizations?per_page=1",
"method": "GET",
"headers": {
"Accept": {
"equalTo": "application/vnd.github+json"
}
}
},
"response": {
"status": 200,
"bodyFileName": "2-organizations.json",
"headers": {
"Date": "Sun, 16 Feb 2025 09:01:25 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/\"575d7c16fc728d88180cb71aecfb2c215cdf28f0259a6eac1d93c607816f3722\"",
"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",
"X-Accepted-OAuth-Scopes": "",
"X-GitHub-Media-Type": "github.v3; format=json",
"x-github-api-version-selected": "2022-11-28",
"X-RateLimit-Limit": "5000",
"X-RateLimit-Remaining": "4960",
"X-RateLimit-Reset": "1739697044",
"X-RateLimit-Used": "40",
"X-RateLimit-Resource": "core",
"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",
"Access-Control-Allow-Origin": "*",
"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'",
"Server": "github.com",
"X-GitHub-Request-Id": "58BE:2FA953:5F36F5:9301D2:67B1A965",
"Link": "<https://api.github.com/organizations?per_page=1&since=44>; rel=\"next\", <https://api.github.com/organizations{?since}>; rel=\"first\""
}
},
"uuid": "87f5d76b-1169-4caf-ab76-04ac6b1e78b9",
"persistent": true,
"insertionIndex": 2
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
{
"id": "950bf65f-6dda-43d1-9ded-907e269024df",
"name": "orgs_errfree",
"request": {
"url": "/orgs/errfree",
"method": "GET",
"headers": {
"Accept": {
"equalTo": "application/vnd.github+json"
}
}
},
"response": {
"status": 200,
"bodyFileName": "3-orgs_errfree.json",
"headers": {
"Date": "Sun, 16 Feb 2025 09:01:25 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/\"fdf38082b2dec2c4293a820e9f615c582c00ca7ab2365a5db1a7f7a3a1905dbd\"",
"Last-Modified": "Wed, 13 May 2020 06:35:19 GMT",
"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",
"X-Accepted-OAuth-Scopes": "admin:org, read:org, repo, user, write:org",
"X-GitHub-Media-Type": "github.v3; format=json",
"x-github-api-version-selected": "2022-11-28",
"X-RateLimit-Limit": "5000",
"X-RateLimit-Remaining": "4959",
"X-RateLimit-Reset": "1739697044",
"X-RateLimit-Used": "41",
"X-RateLimit-Resource": "core",
"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",
"Access-Control-Allow-Origin": "*",
"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'",
"Server": "github.com",
"X-GitHub-Request-Id": "1EF0:22ABA6:638768:974F6C:67B1A965"
}
},
"uuid": "950bf65f-6dda-43d1-9ded-907e269024df",
"persistent": true,
"insertionIndex": 3
}