Skip to content

Commit 8fd5ed5

Browse files
authored
Merge pull request hub4j#644 from martinvanzijl/issue_126_add_type_and_site_admin_fields
Add type and site_admin fields to GHPerson
2 parents 7bc301b + ee2dde4 commit 8fd5ed5

10 files changed

+667
-1
lines changed

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

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,10 @@ public abstract class GHPerson extends GHObject {
2323
protected String login, avatar_url, gravatar_id;
2424

2525
// other fields (that only show up in full data)
26-
protected String location, blog, email, name, company;
26+
protected String location, blog, email, name, company, type;
2727
protected String html_url;
2828
protected int followers, following, public_repos, public_gists;
29+
protected boolean site_admin;
2930

3031
GHPerson wrapUp(GitHub root) {
3132
this.root = root;
@@ -320,4 +321,28 @@ public int getFollowersCount() throws IOException {
320321
populate();
321322
return followers;
322323
}
324+
325+
/**
326+
* Gets the type. This is either "User" or "Organization".
327+
*
328+
* @return the type
329+
* @throws IOException
330+
* the io exception
331+
*/
332+
public String getType() throws IOException {
333+
populate();
334+
return type;
335+
}
336+
337+
/**
338+
* Gets the site_admin field
339+
*
340+
* @return the site_admin field
341+
* @throws IOException
342+
* the io exception
343+
*/
344+
public boolean isSiteAdmin() throws IOException {
345+
populate();
346+
return site_admin;
347+
}
323348
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package org.kohsuke.github;
2+
3+
import org.junit.Test;
4+
5+
import java.io.IOException;
6+
7+
/**
8+
* @author Martin van Zijl
9+
*/
10+
public class GHPersonTest extends AbstractGitHubWireMockTest {
11+
@Test
12+
public void testFieldsForOrganization() throws Exception {
13+
GHRepository repo = getRepository();
14+
GHUser owner = repo.getOwner();
15+
assertEquals("Organization", owner.getType());
16+
assertNotNull(owner.isSiteAdmin());
17+
}
18+
19+
@Test
20+
public void testFieldsForUser() throws Exception {
21+
GHUser user = gitHub.getUser("kohsuke2");
22+
assertEquals("User", user.getType());
23+
assertNotNull(user.isSiteAdmin());
24+
}
25+
26+
protected GHRepository getRepository() throws IOException {
27+
return getRepository(gitHub);
28+
}
29+
30+
private GHRepository getRepository(GitHub gitHub) throws IOException {
31+
return gitHub.getOrganization("github-api-test-org").getRepository("github-api");
32+
}
33+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
{
2+
"login": "github-api-test-org",
3+
"id": 7544739,
4+
"node_id": "MDEyOk9yZ2FuaXphdGlvbjc1NDQ3Mzk=",
5+
"url": "https://api.github.com/orgs/github-api-test-org",
6+
"repos_url": "https://api.github.com/orgs/github-api-test-org/repos",
7+
"events_url": "https://api.github.com/orgs/github-api-test-org/events",
8+
"hooks_url": "https://api.github.com/orgs/github-api-test-org/hooks",
9+
"issues_url": "https://api.github.com/orgs/github-api-test-org/issues",
10+
"members_url": "https://api.github.com/orgs/github-api-test-org/members{/member}",
11+
"public_members_url": "https://api.github.com/orgs/github-api-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": 9,
18+
"public_gists": 0,
19+
"followers": 0,
20+
"following": 0,
21+
"html_url": "https://github.com/github-api-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": 132,
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": 10,
39+
"seats": 0
40+
}
41+
}

src/test/resources/org/kohsuke/github/GHPersonTest/wiremock/testFieldsForOrganization/__files/repos_github-api-test-org_github-api-b3a3dea9-68c7-40d4-8f70-3dddff42e983.json

Lines changed: 331 additions & 0 deletions
Large diffs are not rendered by default.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
{
2+
"login": "github-api-test-org",
3+
"id": 7544739,
4+
"node_id": "MDEyOk9yZ2FuaXphdGlvbjc1NDQ3Mzk=",
5+
"avatar_url": "https://avatars3.githubusercontent.com/u/7544739?v=4",
6+
"gravatar_id": "",
7+
"url": "https://api.github.com/users/github-api-test-org",
8+
"html_url": "https://github.com/github-api-test-org",
9+
"followers_url": "https://api.github.com/users/github-api-test-org/followers",
10+
"following_url": "https://api.github.com/users/github-api-test-org/following{/other_user}",
11+
"gists_url": "https://api.github.com/users/github-api-test-org/gists{/gist_id}",
12+
"starred_url": "https://api.github.com/users/github-api-test-org/starred{/owner}{/repo}",
13+
"subscriptions_url": "https://api.github.com/users/github-api-test-org/subscriptions",
14+
"organizations_url": "https://api.github.com/users/github-api-test-org/orgs",
15+
"repos_url": "https://api.github.com/users/github-api-test-org/repos",
16+
"events_url": "https://api.github.com/users/github-api-test-org/events{/privacy}",
17+
"received_events_url": "https://api.github.com/users/github-api-test-org/received_events",
18+
"type": "Organization",
19+
"site_admin": false,
20+
"name": null,
21+
"company": null,
22+
"blog": "",
23+
"location": null,
24+
"email": null,
25+
"hireable": null,
26+
"bio": null,
27+
"public_repos": 9,
28+
"public_gists": 0,
29+
"followers": 0,
30+
"following": 0,
31+
"created_at": "2014-05-10T19:39:11Z",
32+
"updated_at": "2015-04-20T00:42:30Z",
33+
"plan": {
34+
"name": "free",
35+
"space": 976562499,
36+
"collaborators": 0,
37+
"private_repos": 10000
38+
}
39+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
{
2+
"id": "13f85dbd-5b52-49ce-b65b-bac7d3069c78",
3+
"name": "orgs_github-api-test-org",
4+
"request": {
5+
"url": "/orgs/github-api-test-org",
6+
"method": "GET"
7+
},
8+
"response": {
9+
"status": 200,
10+
"bodyFileName": "orgs_github-api-test-org-13f85dbd-5b52-49ce-b65b-bac7d3069c78.json",
11+
"headers": {
12+
"Date": "Fri, 13 Dec 2019 18:23:29 GMT",
13+
"Content-Type": "application/json; charset=utf-8",
14+
"Server": "GitHub.com",
15+
"Status": "200 OK",
16+
"X-RateLimit-Limit": "5000",
17+
"X-RateLimit-Remaining": "4995",
18+
"X-RateLimit-Reset": "1576264896",
19+
"Cache-Control": "private, max-age=60, s-maxage=60",
20+
"Vary": [
21+
"Accept, Authorization, Cookie, X-GitHub-OTP",
22+
"Accept-Encoding"
23+
],
24+
"ETag": "W/\"30cb8c7d1f87f6928d9c05fbc522398f\"",
25+
"Last-Modified": "Mon, 20 Apr 2015 00:42:30 GMT",
26+
"X-GitHub-Media-Type": "unknown, github.v3",
27+
"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",
28+
"Access-Control-Allow-Origin": "*",
29+
"Strict-Transport-Security": "max-age=31536000; includeSubdomains; preload",
30+
"X-Frame-Options": "deny",
31+
"X-Content-Type-Options": "nosniff",
32+
"X-XSS-Protection": "1; mode=block",
33+
"Referrer-Policy": "origin-when-cross-origin, strict-origin-when-cross-origin",
34+
"Content-Security-Policy": "default-src 'none'",
35+
"X-GitHub-Request-Id": "A5F1:7711:F051A3:112CE43:5DF3D720"
36+
}
37+
},
38+
"uuid": "13f85dbd-5b52-49ce-b65b-bac7d3069c78",
39+
"persistent": true,
40+
"insertionIndex": 1
41+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
{
2+
"id": "b3a3dea9-68c7-40d4-8f70-3dddff42e983",
3+
"name": "repos_github-api-test-org_github-api",
4+
"request": {
5+
"url": "/repos/github-api-test-org/github-api",
6+
"method": "GET"
7+
},
8+
"response": {
9+
"status": 200,
10+
"bodyFileName": "repos_github-api-test-org_github-api-b3a3dea9-68c7-40d4-8f70-3dddff42e983.json",
11+
"headers": {
12+
"Date": "Fri, 13 Dec 2019 18:23:30 GMT",
13+
"Content-Type": "application/json; charset=utf-8",
14+
"Server": "GitHub.com",
15+
"Status": "200 OK",
16+
"X-RateLimit-Limit": "5000",
17+
"X-RateLimit-Remaining": "4994",
18+
"X-RateLimit-Reset": "1576264896",
19+
"Cache-Control": "private, max-age=60, s-maxage=60",
20+
"Vary": [
21+
"Accept, Authorization, Cookie, X-GitHub-OTP",
22+
"Accept-Encoding"
23+
],
24+
"ETag": "W/\"3bab3de79c7a97496a9a2ee8ae63fc60\"",
25+
"Last-Modified": "Thu, 07 Nov 2019 22:27:11 GMT",
26+
"X-GitHub-Media-Type": "unknown, github.v3",
27+
"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",
28+
"Access-Control-Allow-Origin": "*",
29+
"Strict-Transport-Security": "max-age=31536000; includeSubdomains; preload",
30+
"X-Frame-Options": "deny",
31+
"X-Content-Type-Options": "nosniff",
32+
"X-XSS-Protection": "1; mode=block",
33+
"Referrer-Policy": "origin-when-cross-origin, strict-origin-when-cross-origin",
34+
"Content-Security-Policy": "default-src 'none'",
35+
"X-GitHub-Request-Id": "A5F1:7711:F051B2:112CE47:5DF3D721"
36+
}
37+
},
38+
"uuid": "b3a3dea9-68c7-40d4-8f70-3dddff42e983",
39+
"persistent": true,
40+
"insertionIndex": 2
41+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
{
2+
"id": "9edc4a69-96e0-4db6-8469-85483d9ef2c5",
3+
"name": "users_github-api-test-org",
4+
"request": {
5+
"url": "/users/github-api-test-org",
6+
"method": "GET"
7+
},
8+
"response": {
9+
"status": 200,
10+
"bodyFileName": "users_github-api-test-org-9edc4a69-96e0-4db6-8469-85483d9ef2c5.json",
11+
"headers": {
12+
"Date": "Fri, 13 Dec 2019 18:23:30 GMT",
13+
"Content-Type": "application/json; charset=utf-8",
14+
"Server": "GitHub.com",
15+
"Status": "200 OK",
16+
"X-RateLimit-Limit": "5000",
17+
"X-RateLimit-Remaining": "4993",
18+
"X-RateLimit-Reset": "1576264896",
19+
"Cache-Control": "private, max-age=60, s-maxage=60",
20+
"Vary": [
21+
"Accept, Authorization, Cookie, X-GitHub-OTP",
22+
"Accept-Encoding"
23+
],
24+
"ETag": "W/\"5b2acfd788622a6e0078da036013a0eb\"",
25+
"Last-Modified": "Mon, 20 Apr 2015 00:42:30 GMT",
26+
"X-GitHub-Media-Type": "unknown, github.v3",
27+
"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",
28+
"Access-Control-Allow-Origin": "*",
29+
"Strict-Transport-Security": "max-age=31536000; includeSubdomains; preload",
30+
"X-Frame-Options": "deny",
31+
"X-Content-Type-Options": "nosniff",
32+
"X-XSS-Protection": "1; mode=block",
33+
"Referrer-Policy": "origin-when-cross-origin, strict-origin-when-cross-origin",
34+
"Content-Security-Policy": "default-src 'none'",
35+
"X-GitHub-Request-Id": "A5F1:7711:F051B7:112CE55:5DF3D722"
36+
}
37+
},
38+
"uuid": "9edc4a69-96e0-4db6-8469-85483d9ef2c5",
39+
"persistent": true,
40+
"insertionIndex": 3
41+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
{
2+
"login": "kohsuke2",
3+
"id": 1329242,
4+
"node_id": "MDQ6VXNlcjEzMjkyNDI=",
5+
"avatar_url": "https://avatars2.githubusercontent.com/u/1329242?v=4",
6+
"gravatar_id": "",
7+
"url": "https://api.github.com/users/kohsuke2",
8+
"html_url": "https://github.com/kohsuke2",
9+
"followers_url": "https://api.github.com/users/kohsuke2/followers",
10+
"following_url": "https://api.github.com/users/kohsuke2/following{/other_user}",
11+
"gists_url": "https://api.github.com/users/kohsuke2/gists{/gist_id}",
12+
"starred_url": "https://api.github.com/users/kohsuke2/starred{/owner}{/repo}",
13+
"subscriptions_url": "https://api.github.com/users/kohsuke2/subscriptions",
14+
"organizations_url": "https://api.github.com/users/kohsuke2/orgs",
15+
"repos_url": "https://api.github.com/users/kohsuke2/repos",
16+
"events_url": "https://api.github.com/users/kohsuke2/events{/privacy}",
17+
"received_events_url": "https://api.github.com/users/kohsuke2/received_events",
18+
"type": "User",
19+
"site_admin": false,
20+
"name": "Fake 川口耕介",
21+
"company": null,
22+
"blog": "",
23+
"location": null,
24+
"email": null,
25+
"hireable": null,
26+
"bio": null,
27+
"public_repos": 19,
28+
"public_gists": 0,
29+
"followers": 1,
30+
"following": 0,
31+
"created_at": "2012-01-14T01:58:59Z",
32+
"updated_at": "2019-05-16T20:59:50Z"
33+
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
{
2+
"id": "be47bccc-9404-4fe4-be81-ae86857a3c99",
3+
"name": "users_kohsuke2",
4+
"request": {
5+
"url": "/users/kohsuke2",
6+
"method": "GET"
7+
},
8+
"response": {
9+
"status": 200,
10+
"bodyFileName": "users_kohsuke2-be47bccc-9404-4fe4-be81-ae86857a3c99.json",
11+
"headers": {
12+
"Date": "Fri, 13 Dec 2019 18:23:31 GMT",
13+
"Content-Type": "application/json; charset=utf-8",
14+
"Server": "GitHub.com",
15+
"Status": "200 OK",
16+
"X-RateLimit-Limit": "5000",
17+
"X-RateLimit-Remaining": "4992",
18+
"X-RateLimit-Reset": "1576264896",
19+
"Cache-Control": "private, max-age=60, s-maxage=60",
20+
"Vary": [
21+
"Accept, Authorization, Cookie, X-GitHub-OTP",
22+
"Accept-Encoding"
23+
],
24+
"ETag": "W/\"d7eece591c3ac8f84be4eede2c45cddf\"",
25+
"Last-Modified": "Thu, 16 May 2019 20:59:50 GMT",
26+
"X-GitHub-Media-Type": "unknown, github.v3",
27+
"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",
28+
"Access-Control-Allow-Origin": "*",
29+
"Strict-Transport-Security": "max-age=31536000; includeSubdomains; preload",
30+
"X-Frame-Options": "deny",
31+
"X-Content-Type-Options": "nosniff",
32+
"X-XSS-Protection": "1; mode=block",
33+
"Referrer-Policy": "origin-when-cross-origin, strict-origin-when-cross-origin",
34+
"Content-Security-Policy": "default-src 'none'",
35+
"X-GitHub-Request-Id": "A5F3:771A:2C88B78:32D2E33:5DF3D723"
36+
}
37+
},
38+
"uuid": "be47bccc-9404-4fe4-be81-ae86857a3c99",
39+
"persistent": true,
40+
"insertionIndex": 1
41+
}

0 commit comments

Comments
 (0)