From b71aac5f4052cb8d1b315d4cd02ff29ca28ac36e Mon Sep 17 00:00:00 2001 From: t0m4uk1991 Date: Tue, 22 Jun 2021 00:21:56 +0300 Subject: [PATCH 1/3] Add getAppInstallations(/user/installations) method on GHMyself --- .../org/kohsuke/github/GHAppInstallation.java | 5 ++ .../kohsuke/github/GHAppInstallations.java | 21 ++++++++ .../java/org/kohsuke/github/GHMyself.java | 19 +++++++ src/test/java/org/kohsuke/github/AppTest.java | 14 +++++ .../__files/user-1.json | 34 +++++++++++++ .../__files/user-2.json | 34 +++++++++++++ .../__files/user_installations-3.json | 48 +++++++++++++++++ .../mappings/user-1.json | 51 +++++++++++++++++++ .../mappings/user-2.json | 50 ++++++++++++++++++ .../mappings/user_installations-3.json | 47 +++++++++++++++++ 10 files changed, 323 insertions(+) create mode 100644 src/main/java/org/kohsuke/github/GHAppInstallations.java create mode 100644 src/test/resources/org/kohsuke/github/AppTest/wiremock/testGetAppInstallations/__files/user-1.json create mode 100644 src/test/resources/org/kohsuke/github/AppTest/wiremock/testGetAppInstallations/__files/user-2.json create mode 100644 src/test/resources/org/kohsuke/github/AppTest/wiremock/testGetAppInstallations/__files/user_installations-3.json create mode 100644 src/test/resources/org/kohsuke/github/AppTest/wiremock/testGetAppInstallations/mappings/user-1.json create mode 100644 src/test/resources/org/kohsuke/github/AppTest/wiremock/testGetAppInstallations/mappings/user-2.json create mode 100644 src/test/resources/org/kohsuke/github/AppTest/wiremock/testGetAppInstallations/mappings/user_installations-3.json diff --git a/src/main/java/org/kohsuke/github/GHAppInstallation.java b/src/main/java/org/kohsuke/github/GHAppInstallation.java index ecf2c6f5cd..c7cc5d20f4 100644 --- a/src/main/java/org/kohsuke/github/GHAppInstallation.java +++ b/src/main/java/org/kohsuke/github/GHAppInstallation.java @@ -365,4 +365,9 @@ public GHAppCreateTokenBuilder createToken(Map permiss public GHAppCreateTokenBuilder createToken() { return new GHAppCreateTokenBuilder(root, String.format("/app/installations/%d/access_tokens", getId())); } + + GHAppInstallation wrap(GitHub root) { + this.root = root; + return this; + } } diff --git a/src/main/java/org/kohsuke/github/GHAppInstallations.java b/src/main/java/org/kohsuke/github/GHAppInstallations.java new file mode 100644 index 0000000000..ab987a04c3 --- /dev/null +++ b/src/main/java/org/kohsuke/github/GHAppInstallations.java @@ -0,0 +1,21 @@ +package org.kohsuke.github; + +import com.fasterxml.jackson.annotation.JsonProperty; + +import java.util.List; + +public class GHAppInstallations { + + @JsonProperty("total_count") + private int totalCount; + + private List installations; + + public int getTotalCount() { + return this.totalCount; + } + + public List getInstallations() { + return this.installations; + } +} diff --git a/src/main/java/org/kohsuke/github/GHMyself.java b/src/main/java/org/kohsuke/github/GHMyself.java index d827efb307..2bbc106601 100644 --- a/src/main/java/org/kohsuke/github/GHMyself.java +++ b/src/main/java/org/kohsuke/github/GHMyself.java @@ -239,4 +239,23 @@ public GHMembership getMembership(GHOrganization o) throws IOException { //// new Requester(root,ApiVersion.V3).withCredential().to("/user/emails"); // root.retrieveWithAuth3() // } + + /** + * Lists installations of your GitHub App that the authenticated user has explicit permission to access. You must + * use a user-to-server OAuth access token, created for a user who has authorized your GitHub App, to access this + * endpoint. + * + * @throws IOException + * the io exception + * @return list of GHAppInstallation + * @see List + * app installations accessible to the user access token + */ + public List getAppInstallations() throws IOException { + GHAppInstallations ghAppInstallations = root.createRequest() + .withUrlPath("/user/installations") + .fetch(GHAppInstallations.class); + return ghAppInstallations.getInstallations(); + } } diff --git a/src/test/java/org/kohsuke/github/AppTest.java b/src/test/java/org/kohsuke/github/AppTest.java index 331f12eaa9..42cd2a4f40 100755 --- a/src/test/java/org/kohsuke/github/AppTest.java +++ b/src/test/java/org/kohsuke/github/AppTest.java @@ -384,6 +384,20 @@ public void testFetchPullRequestAsList() throws Exception { assertThat(prs, is(not(empty()))); } + @Test + public void testGetAppInstallations() throws Exception { + // To generate test data user-to-server OAuth access token was used + // For more details pls read + // https://docs.github.com/en/developers/apps/building-github-apps/identifying-and-authorizing-users-for-github-apps#identifying-users-on-your-site + final List appInstallation = gitHub.getMyself().getAppInstallations(); + + assertThat(appInstallation, is(not(empty()))); + assertThat(appInstallation.size(), is(1)); + final GHAppInstallation ghAppInstallation = appInstallation.get(0); + assertThat(ghAppInstallation.getAppId(), is(122478L)); + assertThat(ghAppInstallation.getAccount().getLogin(), is("t0m4uk1991")); + } + @Ignore("Needs mocking check") @Test public void testRepoPermissions() throws Exception { diff --git a/src/test/resources/org/kohsuke/github/AppTest/wiremock/testGetAppInstallations/__files/user-1.json b/src/test/resources/org/kohsuke/github/AppTest/wiremock/testGetAppInstallations/__files/user-1.json new file mode 100644 index 0000000000..6929091fa2 --- /dev/null +++ b/src/test/resources/org/kohsuke/github/AppTest/wiremock/testGetAppInstallations/__files/user-1.json @@ -0,0 +1,34 @@ +{ + "login": "t0m4uk1991", + "id": 6698785, + "node_id": "MDQ6VXNlcjY2OTg3ODU=", + "avatar_url": "https://avatars.githubusercontent.com/u/6698785?v=4", + "gravatar_id": "", + "url": "https://api.github.com/users/t0m4uk1991", + "html_url": "https://github.com/t0m4uk1991", + "followers_url": "https://api.github.com/users/t0m4uk1991/followers", + "following_url": "https://api.github.com/users/t0m4uk1991/following{/other_user}", + "gists_url": "https://api.github.com/users/t0m4uk1991/gists{/gist_id}", + "starred_url": "https://api.github.com/users/t0m4uk1991/starred{/owner}{/repo}", + "subscriptions_url": "https://api.github.com/users/t0m4uk1991/subscriptions", + "organizations_url": "https://api.github.com/users/t0m4uk1991/orgs", + "repos_url": "https://api.github.com/users/t0m4uk1991/repos", + "events_url": "https://api.github.com/users/t0m4uk1991/events{/privacy}", + "received_events_url": "https://api.github.com/users/t0m4uk1991/received_events", + "type": "User", + "site_admin": false, + "name": null, + "company": null, + "blog": "https://t0m4uk1991.github.io", + "location": "Ukraine", + "email": "t0m4uk1991@gmail.com", + "hireable": true, + "bio": null, + "twitter_username": null, + "public_repos": 14, + "public_gists": 10, + "followers": 2, + "following": 2, + "created_at": "2014-02-16T20:43:03Z", + "updated_at": "2021-06-21T14:53:32Z" +} \ No newline at end of file diff --git a/src/test/resources/org/kohsuke/github/AppTest/wiremock/testGetAppInstallations/__files/user-2.json b/src/test/resources/org/kohsuke/github/AppTest/wiremock/testGetAppInstallations/__files/user-2.json new file mode 100644 index 0000000000..6929091fa2 --- /dev/null +++ b/src/test/resources/org/kohsuke/github/AppTest/wiremock/testGetAppInstallations/__files/user-2.json @@ -0,0 +1,34 @@ +{ + "login": "t0m4uk1991", + "id": 6698785, + "node_id": "MDQ6VXNlcjY2OTg3ODU=", + "avatar_url": "https://avatars.githubusercontent.com/u/6698785?v=4", + "gravatar_id": "", + "url": "https://api.github.com/users/t0m4uk1991", + "html_url": "https://github.com/t0m4uk1991", + "followers_url": "https://api.github.com/users/t0m4uk1991/followers", + "following_url": "https://api.github.com/users/t0m4uk1991/following{/other_user}", + "gists_url": "https://api.github.com/users/t0m4uk1991/gists{/gist_id}", + "starred_url": "https://api.github.com/users/t0m4uk1991/starred{/owner}{/repo}", + "subscriptions_url": "https://api.github.com/users/t0m4uk1991/subscriptions", + "organizations_url": "https://api.github.com/users/t0m4uk1991/orgs", + "repos_url": "https://api.github.com/users/t0m4uk1991/repos", + "events_url": "https://api.github.com/users/t0m4uk1991/events{/privacy}", + "received_events_url": "https://api.github.com/users/t0m4uk1991/received_events", + "type": "User", + "site_admin": false, + "name": null, + "company": null, + "blog": "https://t0m4uk1991.github.io", + "location": "Ukraine", + "email": "t0m4uk1991@gmail.com", + "hireable": true, + "bio": null, + "twitter_username": null, + "public_repos": 14, + "public_gists": 10, + "followers": 2, + "following": 2, + "created_at": "2014-02-16T20:43:03Z", + "updated_at": "2021-06-21T14:53:32Z" +} \ No newline at end of file diff --git a/src/test/resources/org/kohsuke/github/AppTest/wiremock/testGetAppInstallations/__files/user_installations-3.json b/src/test/resources/org/kohsuke/github/AppTest/wiremock/testGetAppInstallations/__files/user_installations-3.json new file mode 100644 index 0000000000..908e9ca83d --- /dev/null +++ b/src/test/resources/org/kohsuke/github/AppTest/wiremock/testGetAppInstallations/__files/user_installations-3.json @@ -0,0 +1,48 @@ +{ + "total_count": 1, + "installations": [ + { + "id": 17761138, + "account": { + "login": "t0m4uk1991", + "id": 6698785, + "node_id": "MDQ6VXNlcjY2OTg3ODU=", + "avatar_url": "https://avatars.githubusercontent.com/u/6698785?v=4", + "gravatar_id": "", + "url": "https://api.github.com/users/t0m4uk1991", + "html_url": "https://github.com/t0m4uk1991", + "followers_url": "https://api.github.com/users/t0m4uk1991/followers", + "following_url": "https://api.github.com/users/t0m4uk1991/following{/other_user}", + "gists_url": "https://api.github.com/users/t0m4uk1991/gists{/gist_id}", + "starred_url": "https://api.github.com/users/t0m4uk1991/starred{/owner}{/repo}", + "subscriptions_url": "https://api.github.com/users/t0m4uk1991/subscriptions", + "organizations_url": "https://api.github.com/users/t0m4uk1991/orgs", + "repos_url": "https://api.github.com/users/t0m4uk1991/repos", + "events_url": "https://api.github.com/users/t0m4uk1991/events{/privacy}", + "received_events_url": "https://api.github.com/users/t0m4uk1991/received_events", + "type": "User", + "site_admin": false + }, + "repository_selection": "selected", + "access_tokens_url": "https://api.github.com/app/installations/17761138/access_tokens", + "repositories_url": "https://api.github.com/installation/repositories", + "html_url": "https://github.com/settings/installations/17761138", + "app_id": 122478, + "app_slug": "hub4j-github-api-test", + "target_id": 6698785, + "target_type": "User", + "permissions": { + "metadata": "read", + "administration": "read" + }, + "events": [], + "created_at": "2021-06-21T17:39:33.000+03:00", + "updated_at": "2021-06-21T17:39:33.000+03:00", + "single_file_name": null, + "has_multiple_single_files": false, + "single_file_paths": [], + "suspended_by": null, + "suspended_at": null + } + ] +} \ No newline at end of file diff --git a/src/test/resources/org/kohsuke/github/AppTest/wiremock/testGetAppInstallations/mappings/user-1.json b/src/test/resources/org/kohsuke/github/AppTest/wiremock/testGetAppInstallations/mappings/user-1.json new file mode 100644 index 0000000000..aef8226f9c --- /dev/null +++ b/src/test/resources/org/kohsuke/github/AppTest/wiremock/testGetAppInstallations/mappings/user-1.json @@ -0,0 +1,51 @@ +{ + "id": "04c78e0b-2ca2-4f06-b281-956eaba032bd", + "name": "user", + "request": { + "url": "/user", + "method": "GET", + "headers": { + "Accept": { + "equalTo": "text/html, image/gif, image/jpeg, *; q=.2, */*; q=.2" + } + } + }, + "response": { + "status": 200, + "bodyFileName": "user-1.json", + "headers": { + "Server": "GitHub.com", + "Date": "Mon, 21 Jun 2021 20:51:32 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/\"e9e4780f1b19e9323e73a0f5690bf7b59ee956f536ee5a303eb8657423123051\"", + "Last-Modified": "Mon, 21 Jun 2021 14:53:32 GMT", + "X-OAuth-Scopes": "", + "X-Accepted-OAuth-Scopes": "", + "x-oauth-client-id": "Iv1.d1d44ef7894694c0", + "X-GitHub-Media-Type": "unknown, github.v3", + "X-RateLimit-Limit": "5000", + "X-RateLimit-Remaining": "4999", + "X-RateLimit-Reset": "1624312292", + "X-RateLimit-Used": "1", + "X-RateLimit-Resource": "core", + "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'", + "X-GitHub-Request-Id": "2B69:2FF5:2E0782:302E02:60D0FBD4" + } + }, + "uuid": "04c78e0b-2ca2-4f06-b281-956eaba032bd", + "persistent": true, + "scenarioName": "scenario-1-user", + "requiredScenarioState": "Started", + "newScenarioState": "scenario-1-user-2", + "insertionIndex": 1 +} \ No newline at end of file diff --git a/src/test/resources/org/kohsuke/github/AppTest/wiremock/testGetAppInstallations/mappings/user-2.json b/src/test/resources/org/kohsuke/github/AppTest/wiremock/testGetAppInstallations/mappings/user-2.json new file mode 100644 index 0000000000..a98a10990b --- /dev/null +++ b/src/test/resources/org/kohsuke/github/AppTest/wiremock/testGetAppInstallations/mappings/user-2.json @@ -0,0 +1,50 @@ +{ + "id": "c209281c-5bd1-405a-9dc7-34227ec4d5ae", + "name": "user", + "request": { + "url": "/user", + "method": "GET", + "headers": { + "Accept": { + "equalTo": "text/html, image/gif, image/jpeg, *; q=.2, */*; q=.2" + } + } + }, + "response": { + "status": 200, + "bodyFileName": "user-2.json", + "headers": { + "Server": "GitHub.com", + "Date": "Mon, 21 Jun 2021 20:51:33 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/\"e9e4780f1b19e9323e73a0f5690bf7b59ee956f536ee5a303eb8657423123051\"", + "Last-Modified": "Mon, 21 Jun 2021 14:53:32 GMT", + "X-OAuth-Scopes": "", + "X-Accepted-OAuth-Scopes": "", + "x-oauth-client-id": "Iv1.d1d44ef7894694c0", + "X-GitHub-Media-Type": "unknown, github.v3", + "X-RateLimit-Limit": "5000", + "X-RateLimit-Remaining": "4997", + "X-RateLimit-Reset": "1624312292", + "X-RateLimit-Used": "3", + "X-RateLimit-Resource": "core", + "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'", + "X-GitHub-Request-Id": "04D3:4B1B:1F3F8F:200584:60D0FBD4" + } + }, + "uuid": "c209281c-5bd1-405a-9dc7-34227ec4d5ae", + "persistent": true, + "scenarioName": "scenario-1-user", + "requiredScenarioState": "scenario-1-user-2", + "insertionIndex": 2 +} \ No newline at end of file diff --git a/src/test/resources/org/kohsuke/github/AppTest/wiremock/testGetAppInstallations/mappings/user_installations-3.json b/src/test/resources/org/kohsuke/github/AppTest/wiremock/testGetAppInstallations/mappings/user_installations-3.json new file mode 100644 index 0000000000..29af79a9d1 --- /dev/null +++ b/src/test/resources/org/kohsuke/github/AppTest/wiremock/testGetAppInstallations/mappings/user_installations-3.json @@ -0,0 +1,47 @@ +{ + "id": "179e0b84-8037-4d0b-9833-c8ef1b226592", + "name": "user_installations", + "request": { + "url": "/user/installations", + "method": "GET", + "headers": { + "Accept": { + "equalTo": "text/html, image/gif, image/jpeg, *; q=.2, */*; q=.2" + } + } + }, + "response": { + "status": 200, + "bodyFileName": "user_installations-3.json", + "headers": { + "Server": "GitHub.com", + "Date": "Mon, 21 Jun 2021 20:51:33 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/\"05762b67c1a69e46ee710171fdb32872b44904cc7c68a7617c134a6c5eee2b13\"", + "X-OAuth-Scopes": "", + "X-Accepted-OAuth-Scopes": "", + "x-oauth-client-id": "Iv1.d1d44ef7894694c0", + "X-GitHub-Media-Type": "unknown, github.v3", + "X-RateLimit-Limit": "5000", + "X-RateLimit-Remaining": "4996", + "X-RateLimit-Reset": "1624312292", + "X-RateLimit-Used": "4", + "X-RateLimit-Resource": "core", + "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'", + "X-GitHub-Request-Id": "0A50:20B4:B38D2B:B6B016:60D0FBD5" + } + }, + "uuid": "179e0b84-8037-4d0b-9833-c8ef1b226592", + "persistent": true, + "insertionIndex": 3 +} \ No newline at end of file From 81ac4806bb3b67b5b17198e5bce3d90f25064d7a Mon Sep 17 00:00:00 2001 From: t0m4uk1991 Date: Tue, 22 Jun 2021 20:05:31 +0300 Subject: [PATCH 2/3] Update getAppInstallations in GHMyself to return PagedIterable response. --- .../kohsuke/github/GHAppInstallations.java | 21 -------- .../github/GHAppInstallationsIterable.java | 48 +++++++++++++++++++ .../github/GHAppInstallationsPage.java | 20 ++++++++ .../java/org/kohsuke/github/GHMyself.java | 11 ++--- src/test/java/org/kohsuke/github/AppTest.java | 8 ++-- 5 files changed, 75 insertions(+), 33 deletions(-) delete mode 100644 src/main/java/org/kohsuke/github/GHAppInstallations.java create mode 100644 src/main/java/org/kohsuke/github/GHAppInstallationsIterable.java create mode 100644 src/main/java/org/kohsuke/github/GHAppInstallationsPage.java diff --git a/src/main/java/org/kohsuke/github/GHAppInstallations.java b/src/main/java/org/kohsuke/github/GHAppInstallations.java deleted file mode 100644 index ab987a04c3..0000000000 --- a/src/main/java/org/kohsuke/github/GHAppInstallations.java +++ /dev/null @@ -1,21 +0,0 @@ -package org.kohsuke.github; - -import com.fasterxml.jackson.annotation.JsonProperty; - -import java.util.List; - -public class GHAppInstallations { - - @JsonProperty("total_count") - private int totalCount; - - private List installations; - - public int getTotalCount() { - return this.totalCount; - } - - public List getInstallations() { - return this.installations; - } -} diff --git a/src/main/java/org/kohsuke/github/GHAppInstallationsIterable.java b/src/main/java/org/kohsuke/github/GHAppInstallationsIterable.java new file mode 100644 index 0000000000..df82248d1a --- /dev/null +++ b/src/main/java/org/kohsuke/github/GHAppInstallationsIterable.java @@ -0,0 +1,48 @@ +package org.kohsuke.github; + +import java.net.MalformedURLException; +import java.util.Iterator; + +import javax.annotation.Nonnull; + +/** + * Iterable for GHAppInstallation listing. + */ +class GHAppInstallationsIterable extends PagedIterable { + public static final String APP_INSTALLATIONS_URL = "/user/installations"; + private final transient GitHub root; + private GHAppInstallationsPage result; + + public GHAppInstallationsIterable(GitHub root) { + this.root = root; + } + + @Nonnull + @Override + public PagedIterator _iterator(int pageSize) { + try { + final GitHubRequest request = root.createRequest().withUrlPath(APP_INSTALLATIONS_URL).build(); + return new PagedIterator<>( + adapt(GitHubPageIterator.create(root.getClient(), GHAppInstallationsPage.class, request, pageSize)), + null); + } catch (MalformedURLException e) { + throw new GHException("Malformed URL", e); + } + } + + protected Iterator adapt(final Iterator base) { + return new Iterator() { + public boolean hasNext() { + return base.hasNext(); + } + + public GHAppInstallation[] next() { + GHAppInstallationsPage v = base.next(); + if (result == null) { + result = v; + } + return v.getInstallations(root); + } + }; + } +} diff --git a/src/main/java/org/kohsuke/github/GHAppInstallationsPage.java b/src/main/java/org/kohsuke/github/GHAppInstallationsPage.java new file mode 100644 index 0000000000..f17acf7b99 --- /dev/null +++ b/src/main/java/org/kohsuke/github/GHAppInstallationsPage.java @@ -0,0 +1,20 @@ +package org.kohsuke.github; + +/** + * Represents the one page of GHAppInstallations. + */ +class GHAppInstallationsPage { + private int total_count; + private GHAppInstallation[] installations; + + public int getTotalCount() { + return total_count; + } + + GHAppInstallation[] getInstallations(GitHub root) { + for (GHAppInstallation installation : installations) { + installation.wrap(root); + } + return installations; + } +} diff --git a/src/main/java/org/kohsuke/github/GHMyself.java b/src/main/java/org/kohsuke/github/GHMyself.java index 2bbc106601..0cc749df35 100644 --- a/src/main/java/org/kohsuke/github/GHMyself.java +++ b/src/main/java/org/kohsuke/github/GHMyself.java @@ -245,17 +245,12 @@ public GHMembership getMembership(GHOrganization o) throws IOException { * use a user-to-server OAuth access token, created for a user who has authorized your GitHub App, to access this * endpoint. * - * @throws IOException - * the io exception - * @return list of GHAppInstallation + * @return the paged iterable * @see List * app installations accessible to the user access token */ - public List getAppInstallations() throws IOException { - GHAppInstallations ghAppInstallations = root.createRequest() - .withUrlPath("/user/installations") - .fetch(GHAppInstallations.class); - return ghAppInstallations.getInstallations(); + public PagedIterable getAppInstallations() { + return new GHAppInstallationsIterable(root); } } diff --git a/src/test/java/org/kohsuke/github/AppTest.java b/src/test/java/org/kohsuke/github/AppTest.java index 42cd2a4f40..68f5379cad 100755 --- a/src/test/java/org/kohsuke/github/AppTest.java +++ b/src/test/java/org/kohsuke/github/AppTest.java @@ -389,11 +389,11 @@ public void testGetAppInstallations() throws Exception { // To generate test data user-to-server OAuth access token was used // For more details pls read // https://docs.github.com/en/developers/apps/building-github-apps/identifying-and-authorizing-users-for-github-apps#identifying-users-on-your-site - final List appInstallation = gitHub.getMyself().getAppInstallations(); + final PagedIterable appInstallation = gitHub.getMyself().getAppInstallations(); - assertThat(appInstallation, is(not(empty()))); - assertThat(appInstallation.size(), is(1)); - final GHAppInstallation ghAppInstallation = appInstallation.get(0); + assertThat(appInstallation.toList(), is(not(empty()))); + assertThat(appInstallation.toList().size(), is(1)); + final GHAppInstallation ghAppInstallation = appInstallation.toList().get(0); assertThat(ghAppInstallation.getAppId(), is(122478L)); assertThat(ghAppInstallation.getAccount().getLogin(), is("t0m4uk1991")); } From 689b2f73608c117d9cce6c9731a3680ebb3da929 Mon Sep 17 00:00:00 2001 From: Liam Newman Date: Tue, 22 Jun 2021 12:44:05 -0700 Subject: [PATCH 3/3] Apply suggestions from code review --- src/main/java/org/kohsuke/github/GHAppInstallation.java | 5 ----- .../java/org/kohsuke/github/GHAppInstallationsIterable.java | 2 +- src/main/java/org/kohsuke/github/GHAppInstallationsPage.java | 5 +---- 3 files changed, 2 insertions(+), 10 deletions(-) diff --git a/src/main/java/org/kohsuke/github/GHAppInstallation.java b/src/main/java/org/kohsuke/github/GHAppInstallation.java index c7cc5d20f4..ecf2c6f5cd 100644 --- a/src/main/java/org/kohsuke/github/GHAppInstallation.java +++ b/src/main/java/org/kohsuke/github/GHAppInstallation.java @@ -365,9 +365,4 @@ public GHAppCreateTokenBuilder createToken(Map permiss public GHAppCreateTokenBuilder createToken() { return new GHAppCreateTokenBuilder(root, String.format("/app/installations/%d/access_tokens", getId())); } - - GHAppInstallation wrap(GitHub root) { - this.root = root; - return this; - } } diff --git a/src/main/java/org/kohsuke/github/GHAppInstallationsIterable.java b/src/main/java/org/kohsuke/github/GHAppInstallationsIterable.java index df82248d1a..0c9ec2202e 100644 --- a/src/main/java/org/kohsuke/github/GHAppInstallationsIterable.java +++ b/src/main/java/org/kohsuke/github/GHAppInstallationsIterable.java @@ -41,7 +41,7 @@ public GHAppInstallation[] next() { if (result == null) { result = v; } - return v.getInstallations(root); + return v.getInstallations(); } }; } diff --git a/src/main/java/org/kohsuke/github/GHAppInstallationsPage.java b/src/main/java/org/kohsuke/github/GHAppInstallationsPage.java index f17acf7b99..14a978d527 100644 --- a/src/main/java/org/kohsuke/github/GHAppInstallationsPage.java +++ b/src/main/java/org/kohsuke/github/GHAppInstallationsPage.java @@ -11,10 +11,7 @@ public int getTotalCount() { return total_count; } - GHAppInstallation[] getInstallations(GitHub root) { - for (GHAppInstallation installation : installations) { - installation.wrap(root); - } + GHAppInstallation[] getInstallations() { return installations; } }