From dee4e6caffca085045b68170d5b4fb03f6f003a4 Mon Sep 17 00:00:00 2001 From: Chew Date: Sun, 7 Jun 2020 00:55:44 -0500 Subject: [PATCH 1/2] Add twitter_username to Person and bio and hireable to User --- .../java/org/kohsuke/github/GHPerson.java | 16 ++++++- src/main/java/org/kohsuke/github/GHUser.java | 13 ++++++ .../java/org/kohsuke/github/GHObjectTest.java | 2 +- .../java/org/kohsuke/github/GHUserTest.java | 7 ++++ .../__files/users_github-1.json | 34 +++++++++++++++ .../mappings/users_github-1.json | 42 +++++++++++++++++++ 6 files changed, 111 insertions(+), 3 deletions(-) create mode 100644 src/test/resources/org/kohsuke/github/GHUserTest/wiremock/verifyBioAndHireable/__files/users_github-1.json create mode 100644 src/test/resources/org/kohsuke/github/GHUserTest/wiremock/verifyBioAndHireable/mappings/users_github-1.json diff --git a/src/main/java/org/kohsuke/github/GHPerson.java b/src/main/java/org/kohsuke/github/GHPerson.java index f1bba9624b..2941c6cd23 100644 --- a/src/main/java/org/kohsuke/github/GHPerson.java +++ b/src/main/java/org/kohsuke/github/GHPerson.java @@ -24,10 +24,10 @@ public abstract class GHPerson extends GHObject { protected String login, avatar_url; // other fields (that only show up in full data) - protected String location, blog, email, name, company, type; + protected String location, blog, email, bio, name, company, type, twitter_username; protected String html_url; protected int followers, following, public_repos, public_gists; - protected boolean site_admin; + protected boolean site_admin, hireable; // other fields (that only show up in full data) that require privileged scope protected Integer total_private_repos; @@ -237,6 +237,18 @@ public String getLocation() throws IOException { return location; } + /** + * Gets the Twitter Username of this user, like "GitHub" + * + * @return the Twitter username + * @throws IOException + * the io exception + */ + public String getTwitterUsername() throws IOException { + populate(); + return twitter_username; + } + public Date getCreatedAt() throws IOException { populate(); return super.getCreatedAt(); diff --git a/src/main/java/org/kohsuke/github/GHUser.java b/src/main/java/org/kohsuke/github/GHUser.java index af4ff06390..459d5a9bf5 100644 --- a/src/main/java/org/kohsuke/github/GHUser.java +++ b/src/main/java/org/kohsuke/github/GHUser.java @@ -173,6 +173,19 @@ public boolean isPublicMemberOf(GHOrganization org) { return org.hasPublicMember(this); } + /** + * Returns true if this user is marked as hireable, false otherwise + * + * @return if the user is marked as hireable + */ + public boolean isHireable() { + return hireable; + } + + public String getBio() { + return bio; + } + static GHUser[] wrap(GHUser[] users, GitHub root) { for (GHUser f : users) f.root = root; diff --git a/src/test/java/org/kohsuke/github/GHObjectTest.java b/src/test/java/org/kohsuke/github/GHObjectTest.java index b960bf6ddf..f6cda3a1da 100644 --- a/src/test/java/org/kohsuke/github/GHObjectTest.java +++ b/src/test/java/org/kohsuke/github/GHObjectTest.java @@ -11,7 +11,7 @@ public void test_toString() throws Exception { GHOrganization org = gitHub.getOrganization(GITHUB_API_TEST_ORG); assertThat(org.toString(), containsString( - "login=hub4j-test-org,location=,blog=,email=,name=,company=,type=Organization,followers=0,following=0")); + "login=hub4j-test-org,location=,blog=,email=,bio=,name=,company=,type=Organization,followers=0,following=0,hireable=false")); // getResponseHeaderFields is deprecated but we should not break it. assertThat(org.getResponseHeaderFields(), notNullValue()); diff --git a/src/test/java/org/kohsuke/github/GHUserTest.java b/src/test/java/org/kohsuke/github/GHUserTest.java index 6f3f8d7229..a0d136935f 100644 --- a/src/test/java/org/kohsuke/github/GHUserTest.java +++ b/src/test/java/org/kohsuke/github/GHUserTest.java @@ -102,4 +102,11 @@ public void createAndCountPrivateRepos() throws IOException { repository.delete(); } } + + @Test + public void verifyBioAndHireable() throws IOException { + GHUser u = gitHub.getUser("GitHub"); + assertNotNull(u.getBio()); + assertNotNull(u.isHireable()); + } } diff --git a/src/test/resources/org/kohsuke/github/GHUserTest/wiremock/verifyBioAndHireable/__files/users_github-1.json b/src/test/resources/org/kohsuke/github/GHUserTest/wiremock/verifyBioAndHireable/__files/users_github-1.json new file mode 100644 index 0000000000..1bfd2831b4 --- /dev/null +++ b/src/test/resources/org/kohsuke/github/GHUserTest/wiremock/verifyBioAndHireable/__files/users_github-1.json @@ -0,0 +1,34 @@ +{ + "login": "github", + "id": 9919, + "node_id": "MDEyOk9yZ2FuaXphdGlvbjk5MTk=", + "avatar_url": "https://avatars1.githubusercontent.com/u/9919?v=4", + "gravatar_id": "", + "url": "https://api.github.com/users/github", + "html_url": "https://github.com/github", + "followers_url": "https://api.github.com/users/github/followers", + "following_url": "https://api.github.com/users/github/following{/other_user}", + "gists_url": "https://api.github.com/users/github/gists{/gist_id}", + "starred_url": "https://api.github.com/users/github/starred{/owner}{/repo}", + "subscriptions_url": "https://api.github.com/users/github/subscriptions", + "organizations_url": "https://api.github.com/users/github/orgs", + "repos_url": "https://api.github.com/users/github/repos", + "events_url": "https://api.github.com/users/github/events{/privacy}", + "received_events_url": "https://api.github.com/users/github/received_events", + "type": "Organization", + "site_admin": false, + "name": "GitHub", + "company": null, + "blog": "https://github.com/about", + "location": "San Francisco, CA", + "email": "support@github.com", + "hireable": null, + "bio": "How people build software.", + "twitter_username": null, + "public_repos": 346, + "public_gists": 0, + "followers": 0, + "following": 0, + "created_at": "2008-05-11T04:37:31Z", + "updated_at": "2020-02-07T13:08:07Z" +} \ No newline at end of file diff --git a/src/test/resources/org/kohsuke/github/GHUserTest/wiremock/verifyBioAndHireable/mappings/users_github-1.json b/src/test/resources/org/kohsuke/github/GHUserTest/wiremock/verifyBioAndHireable/mappings/users_github-1.json new file mode 100644 index 0000000000..92817540d9 --- /dev/null +++ b/src/test/resources/org/kohsuke/github/GHUserTest/wiremock/verifyBioAndHireable/mappings/users_github-1.json @@ -0,0 +1,42 @@ +{ + "id": "b0a81aff-fa31-4f8a-8934-5816b7db5d28", + "name": "users_github", + "request": { + "url": "/users/GitHub", + "method": "GET", + "headers": { + "Accept": { + "equalTo": "text/html, image/gif, image/jpeg, *; q=.2, */*; q=.2" + } + } + }, + "response": { + "status": 200, + "bodyFileName": "users_github-1.json", + "headers": { + "server": "GitHub.com", + "date": "Sun, 07 Jun 2020 05:50:33 GMT", + "content-type": "application/json; charset=utf-8", + "status": "200 OK", + "cache-control": "public, max-age=60, s-maxage=60", + "vary": "Accept, Accept-Encoding, Accept, X-Requested-With", + "etag": "W/\"98a98fb1f7b75195fb721356df6181b5\"", + "last-modified": "Fri, 07 Feb 2020 13:08:07 GMT", + "x-github-media-type": "unknown, github.v3", + "strict-transport-security": "max-age=31536000; includeSubdomains; preload", + "x-frame-options": "deny", + "x-content-type-options": "nosniff", + "x-xss-protection": "1; mode=block", + "referrer-policy": "origin-when-cross-origin, strict-origin-when-cross-origin", + "content-security-policy": "default-src 'none'", + "X-Ratelimit-Limit": "60", + "X-Ratelimit-Remaining": "50", + "X-Ratelimit-Reset": "1591510189", + "Accept-Ranges": "bytes", + "X-GitHub-Request-Id": "C067:2C3F:70CA28:11A5488:5EDC8029" + } + }, + "uuid": "b0a81aff-fa31-4f8a-8934-5816b7db5d28", + "persistent": true, + "insertionIndex": 1 +} \ No newline at end of file From c92f5c571371dca02b75747a4b8d6a2bd27bcf53 Mon Sep 17 00:00:00 2001 From: Chew Date: Sun, 7 Jun 2020 15:05:02 -0500 Subject: [PATCH 2/2] Update test value and add new test for Twitter Username --- .../java/org/kohsuke/github/GHUserTest.java | 7 ++-- .../__files/users_chew-1.json | 34 +++++++++++++++++++ .../__files/users_github-1.json | 34 ------------------- ...{users_github-1.json => users_chew-1.json} | 22 ++++++------ 4 files changed, 49 insertions(+), 48 deletions(-) create mode 100644 src/test/resources/org/kohsuke/github/GHUserTest/wiremock/verifyBioAndHireable/__files/users_chew-1.json delete mode 100644 src/test/resources/org/kohsuke/github/GHUserTest/wiremock/verifyBioAndHireable/__files/users_github-1.json rename src/test/resources/org/kohsuke/github/GHUserTest/wiremock/verifyBioAndHireable/mappings/{users_github-1.json => users_chew-1.json} (66%) diff --git a/src/test/java/org/kohsuke/github/GHUserTest.java b/src/test/java/org/kohsuke/github/GHUserTest.java index a0d136935f..d7ed7a8a15 100644 --- a/src/test/java/org/kohsuke/github/GHUserTest.java +++ b/src/test/java/org/kohsuke/github/GHUserTest.java @@ -105,8 +105,9 @@ public void createAndCountPrivateRepos() throws IOException { @Test public void verifyBioAndHireable() throws IOException { - GHUser u = gitHub.getUser("GitHub"); - assertNotNull(u.getBio()); - assertNotNull(u.isHireable()); + GHUser u = gitHub.getUser("Chew"); + assertThat(u.getBio(), equalTo("I like to program things and I hope to program something cool one day :D")); + assertTrue(u.isHireable()); + assertNotNull(u.getTwitterUsername()); } } diff --git a/src/test/resources/org/kohsuke/github/GHUserTest/wiremock/verifyBioAndHireable/__files/users_chew-1.json b/src/test/resources/org/kohsuke/github/GHUserTest/wiremock/verifyBioAndHireable/__files/users_chew-1.json new file mode 100644 index 0000000000..4c0bb1f6e9 --- /dev/null +++ b/src/test/resources/org/kohsuke/github/GHUserTest/wiremock/verifyBioAndHireable/__files/users_chew-1.json @@ -0,0 +1,34 @@ +{ + "login": "Chew", + "id": 8278263, + "node_id": "MDQ6VXNlcjgyNzgyNjM=", + "avatar_url": "https://avatars3.githubusercontent.com/u/8278263?v=4", + "gravatar_id": "", + "url": "https://api.github.com/users/Chew", + "html_url": "https://github.com/Chew", + "followers_url": "https://api.github.com/users/Chew/followers", + "following_url": "https://api.github.com/users/Chew/following{/other_user}", + "gists_url": "https://api.github.com/users/Chew/gists{/gist_id}", + "starred_url": "https://api.github.com/users/Chew/starred{/owner}{/repo}", + "subscriptions_url": "https://api.github.com/users/Chew/subscriptions", + "organizations_url": "https://api.github.com/users/Chew/orgs", + "repos_url": "https://api.github.com/users/Chew/repos", + "events_url": "https://api.github.com/users/Chew/events{/privacy}", + "received_events_url": "https://api.github.com/users/Chew/received_events", + "type": "User", + "site_admin": false, + "name": "Olivia", + "company": "@Memerator", + "blog": "https://chew.pw", + "location": null, + "email": null, + "hireable": true, + "bio": "I like to program things and I hope to program something cool one day :D", + "twitter_username": "ChewCraft", + "public_repos": 96, + "public_gists": 4, + "followers": 29, + "following": 3, + "created_at": "2014-07-26T23:41:36Z", + "updated_at": "2020-06-06T20:16:06Z" +} \ No newline at end of file diff --git a/src/test/resources/org/kohsuke/github/GHUserTest/wiremock/verifyBioAndHireable/__files/users_github-1.json b/src/test/resources/org/kohsuke/github/GHUserTest/wiremock/verifyBioAndHireable/__files/users_github-1.json deleted file mode 100644 index 1bfd2831b4..0000000000 --- a/src/test/resources/org/kohsuke/github/GHUserTest/wiremock/verifyBioAndHireable/__files/users_github-1.json +++ /dev/null @@ -1,34 +0,0 @@ -{ - "login": "github", - "id": 9919, - "node_id": "MDEyOk9yZ2FuaXphdGlvbjk5MTk=", - "avatar_url": "https://avatars1.githubusercontent.com/u/9919?v=4", - "gravatar_id": "", - "url": "https://api.github.com/users/github", - "html_url": "https://github.com/github", - "followers_url": "https://api.github.com/users/github/followers", - "following_url": "https://api.github.com/users/github/following{/other_user}", - "gists_url": "https://api.github.com/users/github/gists{/gist_id}", - "starred_url": "https://api.github.com/users/github/starred{/owner}{/repo}", - "subscriptions_url": "https://api.github.com/users/github/subscriptions", - "organizations_url": "https://api.github.com/users/github/orgs", - "repos_url": "https://api.github.com/users/github/repos", - "events_url": "https://api.github.com/users/github/events{/privacy}", - "received_events_url": "https://api.github.com/users/github/received_events", - "type": "Organization", - "site_admin": false, - "name": "GitHub", - "company": null, - "blog": "https://github.com/about", - "location": "San Francisco, CA", - "email": "support@github.com", - "hireable": null, - "bio": "How people build software.", - "twitter_username": null, - "public_repos": 346, - "public_gists": 0, - "followers": 0, - "following": 0, - "created_at": "2008-05-11T04:37:31Z", - "updated_at": "2020-02-07T13:08:07Z" -} \ No newline at end of file diff --git a/src/test/resources/org/kohsuke/github/GHUserTest/wiremock/verifyBioAndHireable/mappings/users_github-1.json b/src/test/resources/org/kohsuke/github/GHUserTest/wiremock/verifyBioAndHireable/mappings/users_chew-1.json similarity index 66% rename from src/test/resources/org/kohsuke/github/GHUserTest/wiremock/verifyBioAndHireable/mappings/users_github-1.json rename to src/test/resources/org/kohsuke/github/GHUserTest/wiremock/verifyBioAndHireable/mappings/users_chew-1.json index 92817540d9..85044991d8 100644 --- a/src/test/resources/org/kohsuke/github/GHUserTest/wiremock/verifyBioAndHireable/mappings/users_github-1.json +++ b/src/test/resources/org/kohsuke/github/GHUserTest/wiremock/verifyBioAndHireable/mappings/users_chew-1.json @@ -1,8 +1,8 @@ { - "id": "b0a81aff-fa31-4f8a-8934-5816b7db5d28", - "name": "users_github", + "id": "39860a04-002b-45da-aae7-70c97031c79e", + "name": "users_chew", "request": { - "url": "/users/GitHub", + "url": "/users/Chew", "method": "GET", "headers": { "Accept": { @@ -12,16 +12,16 @@ }, "response": { "status": 200, - "bodyFileName": "users_github-1.json", + "bodyFileName": "users_chew-1.json", "headers": { "server": "GitHub.com", - "date": "Sun, 07 Jun 2020 05:50:33 GMT", + "date": "Sun, 07 Jun 2020 19:58:59 GMT", "content-type": "application/json; charset=utf-8", "status": "200 OK", "cache-control": "public, max-age=60, s-maxage=60", "vary": "Accept, Accept-Encoding, Accept, X-Requested-With", - "etag": "W/\"98a98fb1f7b75195fb721356df6181b5\"", - "last-modified": "Fri, 07 Feb 2020 13:08:07 GMT", + "etag": "W/\"960f568b7a2dd1591a136e36748cc44e\"", + "last-modified": "Sat, 06 Jun 2020 20:16:06 GMT", "x-github-media-type": "unknown, github.v3", "strict-transport-security": "max-age=31536000; includeSubdomains; preload", "x-frame-options": "deny", @@ -30,13 +30,13 @@ "referrer-policy": "origin-when-cross-origin, strict-origin-when-cross-origin", "content-security-policy": "default-src 'none'", "X-Ratelimit-Limit": "60", - "X-Ratelimit-Remaining": "50", - "X-Ratelimit-Reset": "1591510189", + "X-Ratelimit-Remaining": "59", + "X-Ratelimit-Reset": "1591563539", "Accept-Ranges": "bytes", - "X-GitHub-Request-Id": "C067:2C3F:70CA28:11A5488:5EDC8029" + "X-GitHub-Request-Id": "C2D3:7B67:11221D7:27FD7A4:5EDD4703" } }, - "uuid": "b0a81aff-fa31-4f8a-8934-5816b7db5d28", + "uuid": "39860a04-002b-45da-aae7-70c97031c79e", "persistent": true, "insertionIndex": 1 } \ No newline at end of file