From 74fd004e478c906e8f1bbe840449951b8c6c7f87 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Yoann=20Rodi=C3=A8re?= Date: Wed, 21 Sep 2022 17:18:31 +0200 Subject: [PATCH] Add GitHub#getInstallation to access endpoints related to the authenticated installation --- .../org/kohsuke/github/GHAppInstallation.java | 9 + .../GHAuthenticatedAppInstallation.java | 40 ++++ src/main/java/org/kohsuke/github/GitHub.java | 16 ++ .../GHAuthenticatedAppInstallationTest.java | 32 +++ .../__files/app-1.json | 37 +++ .../__files/installation_repositories-4.json | 218 ++++++++++++++++++ .../orgs_hub4j-test-org_installation-2.json | 40 ++++ .../mappings/app-1.json | 39 ++++ ...nstallations_12129901_access_tokens-3.json | 46 ++++ .../mappings/installation_repositories-4.json | 44 ++++ .../orgs_hub4j-test-org_installation-2.json | 39 ++++ 11 files changed, 560 insertions(+) create mode 100644 src/main/java/org/kohsuke/github/GHAuthenticatedAppInstallation.java create mode 100644 src/test/java/org/kohsuke/github/GHAuthenticatedAppInstallationTest.java create mode 100644 src/test/resources/org/kohsuke/github/GHAuthenticatedAppInstallationTest/wiremock/testListRepositoriesTwoRepos/__files/app-1.json create mode 100644 src/test/resources/org/kohsuke/github/GHAuthenticatedAppInstallationTest/wiremock/testListRepositoriesTwoRepos/__files/installation_repositories-4.json create mode 100644 src/test/resources/org/kohsuke/github/GHAuthenticatedAppInstallationTest/wiremock/testListRepositoriesTwoRepos/__files/orgs_hub4j-test-org_installation-2.json create mode 100644 src/test/resources/org/kohsuke/github/GHAuthenticatedAppInstallationTest/wiremock/testListRepositoriesTwoRepos/mappings/app-1.json create mode 100644 src/test/resources/org/kohsuke/github/GHAuthenticatedAppInstallationTest/wiremock/testListRepositoriesTwoRepos/mappings/app_installations_12129901_access_tokens-3.json create mode 100644 src/test/resources/org/kohsuke/github/GHAuthenticatedAppInstallationTest/wiremock/testListRepositoriesTwoRepos/mappings/installation_repositories-4.json create mode 100644 src/test/resources/org/kohsuke/github/GHAuthenticatedAppInstallationTest/wiremock/testListRepositoriesTwoRepos/mappings/orgs_hub4j-test-org_installation-2.json diff --git a/src/main/java/org/kohsuke/github/GHAppInstallation.java b/src/main/java/org/kohsuke/github/GHAppInstallation.java index 1c5e5144b9..3f403d29ba 100644 --- a/src/main/java/org/kohsuke/github/GHAppInstallation.java +++ b/src/main/java/org/kohsuke/github/GHAppInstallation.java @@ -117,7 +117,16 @@ public String getRepositoriesUrl() { * List repositories that this app installation can access. * * @return the paged iterable + * @deprecated This method cannot work on a {@link GHAppInstallation} retrieved from + * {@link GHApp#listInstallations()} (for example), except when resorting to unsupported hacks involving + * {@link GHAppInstallation#setRoot(GitHub)} to switch from an application client to an installation + * client. + * This method will be removed. + * You should instead use an installation client (with an installation token, not a JWT), + * retrieve a {@link GHAuthenticatedAppInstallation} from {@link GitHub#getInstallation()}, + * then call {@link GHAuthenticatedAppInstallation#listRepositories()}. */ + @Deprecated @Preview(MACHINE_MAN) public PagedSearchIterable listRepositories() { GitHubRequest request; diff --git a/src/main/java/org/kohsuke/github/GHAuthenticatedAppInstallation.java b/src/main/java/org/kohsuke/github/GHAuthenticatedAppInstallation.java new file mode 100644 index 0000000000..7760b0f87f --- /dev/null +++ b/src/main/java/org/kohsuke/github/GHAuthenticatedAppInstallation.java @@ -0,0 +1,40 @@ +package org.kohsuke.github; + +import javax.annotation.Nonnull; + +import static org.kohsuke.github.internal.Previews.MACHINE_MAN; + +/** + * The Github App Installation corresponding to the installation token used in a client. + * + * @see GitHub#getInstallation() GitHub#getAuthenticatedAppInstallation() + */ +public class GHAuthenticatedAppInstallation extends GitHubInteractiveObject { + protected GHAuthenticatedAppInstallation(@Nonnull GitHub root) { + super(root); + } + + /** + * List repositories that this app installation can access. + * + * @return the paged iterable + */ + @Preview(MACHINE_MAN) + public PagedSearchIterable listRepositories() { + GitHubRequest request; + + request = root().createRequest().withPreview(MACHINE_MAN).withUrlPath("/installation/repositories").build(); + + return new PagedSearchIterable<>(root(), request, GHAuthenticatedAppInstallationRepositoryResult.class); + } + + private static class GHAuthenticatedAppInstallationRepositoryResult extends SearchResult { + private GHRepository[] repositories; + + @Override + GHRepository[] getItems(GitHub root) { + return repositories; + } + } + +} diff --git a/src/main/java/org/kohsuke/github/GitHub.java b/src/main/java/org/kohsuke/github/GitHub.java index 5244cb374d..01a2cf2b20 100644 --- a/src/main/java/org/kohsuke/github/GitHub.java +++ b/src/main/java/org/kohsuke/github/GitHub.java @@ -1160,6 +1160,22 @@ public GHApp getApp() throws IOException { return createRequest().withPreview(MACHINE_MAN).withUrlPath("/app").fetch(GHApp.class); } + /** + * Returns the GitHub App Installation associated with the authentication credentials used. + *

+ * You must use an installation token to access this endpoint; otherwise consider {@link #getApp()} and its various + * ways of retrieving installations. + * + * @return the app + * @throws IOException + * the io exception + * @see GitHub App installations + */ + @Preview(MACHINE_MAN) + public GHAuthenticatedAppInstallation getInstallation() throws IOException { + return new GHAuthenticatedAppInstallation(this); + } + /** * Ensures that the credential is valid. * diff --git a/src/test/java/org/kohsuke/github/GHAuthenticatedAppInstallationTest.java b/src/test/java/org/kohsuke/github/GHAuthenticatedAppInstallationTest.java new file mode 100644 index 0000000000..be547655b6 --- /dev/null +++ b/src/test/java/org/kohsuke/github/GHAuthenticatedAppInstallationTest.java @@ -0,0 +1,32 @@ +package org.kohsuke.github; + +import org.junit.Test; +import org.kohsuke.github.authorization.OrgAppInstallationAuthorizationProvider; + +import java.io.IOException; +import java.util.List; + +import static org.hamcrest.Matchers.arrayContainingInAnyOrder; +import static org.hamcrest.Matchers.equalTo; + +public class GHAuthenticatedAppInstallationTest extends AbstractGHAppInstallationTest { + + @Override + protected GitHubBuilder getGitHubBuilder() { + OrgAppInstallationAuthorizationProvider provider = new OrgAppInstallationAuthorizationProvider("hub4j-test-org", + jwtProvider1); + return super.getGitHubBuilder().withAuthorizationProvider(provider); + } + + @Test + public void testListRepositoriesTwoRepos() throws IOException { + GHAuthenticatedAppInstallation appInstallation = gitHub.getInstallation(); + + List repositories = appInstallation.listRepositories().toList(); + + assertThat(repositories.size(), equalTo(2)); + assertThat(repositories.stream().map(GHRepository::getName).toArray(), + arrayContainingInAnyOrder("empty", "test-readme")); + } + +} diff --git a/src/test/resources/org/kohsuke/github/GHAuthenticatedAppInstallationTest/wiremock/testListRepositoriesTwoRepos/__files/app-1.json b/src/test/resources/org/kohsuke/github/GHAuthenticatedAppInstallationTest/wiremock/testListRepositoriesTwoRepos/__files/app-1.json new file mode 100644 index 0000000000..47e828ca82 --- /dev/null +++ b/src/test/resources/org/kohsuke/github/GHAuthenticatedAppInstallationTest/wiremock/testListRepositoriesTwoRepos/__files/app-1.json @@ -0,0 +1,37 @@ +{ + "id": 82994, + "slug": "ghapi-test-app-1", + "node_id": "MDM6QXBwODI5OTQ=", + "owner": { + "login": "hub4j-test-org", + "id": 7544739, + "node_id": "MDEyOk9yZ2FuaXphdGlvbjc1NDQ3Mzk=", + "avatar_url": "https://avatars.githubusercontent.com/u/7544739?v=4", + "gravatar_id": "", + "url": "https://api.github.com/users/hub4j-test-org", + "html_url": "https://github.com/hub4j-test-org", + "followers_url": "https://api.github.com/users/hub4j-test-org/followers", + "following_url": "https://api.github.com/users/hub4j-test-org/following{/other_user}", + "gists_url": "https://api.github.com/users/hub4j-test-org/gists{/gist_id}", + "starred_url": "https://api.github.com/users/hub4j-test-org/starred{/owner}{/repo}", + "subscriptions_url": "https://api.github.com/users/hub4j-test-org/subscriptions", + "organizations_url": "https://api.github.com/users/hub4j-test-org/orgs", + "repos_url": "https://api.github.com/users/hub4j-test-org/repos", + "events_url": "https://api.github.com/users/hub4j-test-org/events{/privacy}", + "received_events_url": "https://api.github.com/users/hub4j-test-org/received_events", + "type": "Organization", + "site_admin": false + }, + "name": "GHApi Test app 1", + "description": "", + "external_url": "http://localhost", + "html_url": "https://github.com/apps/ghapi-test-app-1", + "created_at": "2020-09-30T13:40:56Z", + "updated_at": "2020-09-30T13:40:56Z", + "permissions": { + "contents": "read", + "metadata": "read" + }, + "events": [], + "installations_count": 1 +} \ No newline at end of file diff --git a/src/test/resources/org/kohsuke/github/GHAuthenticatedAppInstallationTest/wiremock/testListRepositoriesTwoRepos/__files/installation_repositories-4.json b/src/test/resources/org/kohsuke/github/GHAuthenticatedAppInstallationTest/wiremock/testListRepositoriesTwoRepos/__files/installation_repositories-4.json new file mode 100644 index 0000000000..b2cf6a43ce --- /dev/null +++ b/src/test/resources/org/kohsuke/github/GHAuthenticatedAppInstallationTest/wiremock/testListRepositoriesTwoRepos/__files/installation_repositories-4.json @@ -0,0 +1,218 @@ +{ + "total_count": 2, + "repository_selection": "selected", + "repositories": [ + { + "id": 60391080, + "node_id": "MDEwOlJlcG9zaXRvcnk2MDM5MTA4MA==", + "name": "empty", + "full_name": "hub4j-test-org/empty", + "private": false, + "owner": { + "login": "hub4j-test-org", + "id": 7544739, + "node_id": "MDEyOk9yZ2FuaXphdGlvbjc1NDQ3Mzk=", + "avatar_url": "https://avatars.githubusercontent.com/u/7544739?v=4", + "gravatar_id": "", + "url": "https://api.github.com/users/hub4j-test-org", + "html_url": "https://github.com/hub4j-test-org", + "followers_url": "https://api.github.com/users/hub4j-test-org/followers", + "following_url": "https://api.github.com/users/hub4j-test-org/following{/other_user}", + "gists_url": "https://api.github.com/users/hub4j-test-org/gists{/gist_id}", + "starred_url": "https://api.github.com/users/hub4j-test-org/starred{/owner}{/repo}", + "subscriptions_url": "https://api.github.com/users/hub4j-test-org/subscriptions", + "organizations_url": "https://api.github.com/users/hub4j-test-org/orgs", + "repos_url": "https://api.github.com/users/hub4j-test-org/repos", + "events_url": "https://api.github.com/users/hub4j-test-org/events{/privacy}", + "received_events_url": "https://api.github.com/users/hub4j-test-org/received_events", + "type": "Organization", + "site_admin": false + }, + "html_url": "https://github.com/hub4j-test-org/empty", + "description": "Repository that has no contributor", + "fork": false, + "url": "https://api.github.com/repos/hub4j-test-org/empty", + "forks_url": "https://api.github.com/repos/hub4j-test-org/empty/forks", + "keys_url": "https://api.github.com/repos/hub4j-test-org/empty/keys{/key_id}", + "collaborators_url": "https://api.github.com/repos/hub4j-test-org/empty/collaborators{/collaborator}", + "teams_url": "https://api.github.com/repos/hub4j-test-org/empty/teams", + "hooks_url": "https://api.github.com/repos/hub4j-test-org/empty/hooks", + "issue_events_url": "https://api.github.com/repos/hub4j-test-org/empty/issues/events{/number}", + "events_url": "https://api.github.com/repos/hub4j-test-org/empty/events", + "assignees_url": "https://api.github.com/repos/hub4j-test-org/empty/assignees{/user}", + "branches_url": "https://api.github.com/repos/hub4j-test-org/empty/branches{/branch}", + "tags_url": "https://api.github.com/repos/hub4j-test-org/empty/tags", + "blobs_url": "https://api.github.com/repos/hub4j-test-org/empty/git/blobs{/sha}", + "git_tags_url": "https://api.github.com/repos/hub4j-test-org/empty/git/tags{/sha}", + "git_refs_url": "https://api.github.com/repos/hub4j-test-org/empty/git/refs{/sha}", + "trees_url": "https://api.github.com/repos/hub4j-test-org/empty/git/trees{/sha}", + "statuses_url": "https://api.github.com/repos/hub4j-test-org/empty/statuses/{sha}", + "languages_url": "https://api.github.com/repos/hub4j-test-org/empty/languages", + "stargazers_url": "https://api.github.com/repos/hub4j-test-org/empty/stargazers", + "contributors_url": "https://api.github.com/repos/hub4j-test-org/empty/contributors", + "subscribers_url": "https://api.github.com/repos/hub4j-test-org/empty/subscribers", + "subscription_url": "https://api.github.com/repos/hub4j-test-org/empty/subscription", + "commits_url": "https://api.github.com/repos/hub4j-test-org/empty/commits{/sha}", + "git_commits_url": "https://api.github.com/repos/hub4j-test-org/empty/git/commits{/sha}", + "comments_url": "https://api.github.com/repos/hub4j-test-org/empty/comments{/number}", + "issue_comment_url": "https://api.github.com/repos/hub4j-test-org/empty/issues/comments{/number}", + "contents_url": "https://api.github.com/repos/hub4j-test-org/empty/contents/{+path}", + "compare_url": "https://api.github.com/repos/hub4j-test-org/empty/compare/{base}...{head}", + "merges_url": "https://api.github.com/repos/hub4j-test-org/empty/merges", + "archive_url": "https://api.github.com/repos/hub4j-test-org/empty/{archive_format}{/ref}", + "downloads_url": "https://api.github.com/repos/hub4j-test-org/empty/downloads", + "issues_url": "https://api.github.com/repos/hub4j-test-org/empty/issues{/number}", + "pulls_url": "https://api.github.com/repos/hub4j-test-org/empty/pulls{/number}", + "milestones_url": "https://api.github.com/repos/hub4j-test-org/empty/milestones{/number}", + "notifications_url": "https://api.github.com/repos/hub4j-test-org/empty/notifications{?since,all,participating}", + "labels_url": "https://api.github.com/repos/hub4j-test-org/empty/labels{/name}", + "releases_url": "https://api.github.com/repos/hub4j-test-org/empty/releases{/id}", + "deployments_url": "https://api.github.com/repos/hub4j-test-org/empty/deployments", + "created_at": "2016-06-04T03:22:22Z", + "updated_at": "2016-06-04T03:22:22Z", + "pushed_at": "2016-06-04T03:22:23Z", + "git_url": "git://github.com/hub4j-test-org/empty.git", + "ssh_url": "git@github.com:hub4j-test-org/empty.git", + "clone_url": "https://github.com/hub4j-test-org/empty.git", + "svn_url": "https://github.com/hub4j-test-org/empty", + "homepage": null, + "size": 0, + "stargazers_count": 0, + "watchers_count": 0, + "language": null, + "has_issues": true, + "has_projects": true, + "has_downloads": true, + "has_wiki": true, + "has_pages": false, + "forks_count": 0, + "mirror_url": null, + "archived": false, + "disabled": false, + "open_issues_count": 0, + "license": null, + "allow_forking": true, + "is_template": false, + "web_commit_signoff_required": false, + "topics": [], + "visibility": "public", + "forks": 0, + "open_issues": 0, + "watchers": 0, + "default_branch": "master", + "permissions": { + "admin": false, + "maintain": false, + "push": false, + "triage": false, + "pull": false + } + }, + { + "id": 30829547, + "node_id": "MDEwOlJlcG9zaXRvcnkzMDgyOTU0Nw==", + "name": "test-readme", + "full_name": "hub4j-test-org/test-readme", + "private": false, + "owner": { + "login": "hub4j-test-org", + "id": 7544739, + "node_id": "MDEyOk9yZ2FuaXphdGlvbjc1NDQ3Mzk=", + "avatar_url": "https://avatars.githubusercontent.com/u/7544739?v=4", + "gravatar_id": "", + "url": "https://api.github.com/users/hub4j-test-org", + "html_url": "https://github.com/hub4j-test-org", + "followers_url": "https://api.github.com/users/hub4j-test-org/followers", + "following_url": "https://api.github.com/users/hub4j-test-org/following{/other_user}", + "gists_url": "https://api.github.com/users/hub4j-test-org/gists{/gist_id}", + "starred_url": "https://api.github.com/users/hub4j-test-org/starred{/owner}{/repo}", + "subscriptions_url": "https://api.github.com/users/hub4j-test-org/subscriptions", + "organizations_url": "https://api.github.com/users/hub4j-test-org/orgs", + "repos_url": "https://api.github.com/users/hub4j-test-org/repos", + "events_url": "https://api.github.com/users/hub4j-test-org/events{/privacy}", + "received_events_url": "https://api.github.com/users/hub4j-test-org/received_events", + "type": "Organization", + "site_admin": false + }, + "html_url": "https://github.com/hub4j-test-org/test-readme", + "description": "Checks the readme of content", + "fork": false, + "url": "https://api.github.com/repos/hub4j-test-org/test-readme", + "forks_url": "https://api.github.com/repos/hub4j-test-org/test-readme/forks", + "keys_url": "https://api.github.com/repos/hub4j-test-org/test-readme/keys{/key_id}", + "collaborators_url": "https://api.github.com/repos/hub4j-test-org/test-readme/collaborators{/collaborator}", + "teams_url": "https://api.github.com/repos/hub4j-test-org/test-readme/teams", + "hooks_url": "https://api.github.com/repos/hub4j-test-org/test-readme/hooks", + "issue_events_url": "https://api.github.com/repos/hub4j-test-org/test-readme/issues/events{/number}", + "events_url": "https://api.github.com/repos/hub4j-test-org/test-readme/events", + "assignees_url": "https://api.github.com/repos/hub4j-test-org/test-readme/assignees{/user}", + "branches_url": "https://api.github.com/repos/hub4j-test-org/test-readme/branches{/branch}", + "tags_url": "https://api.github.com/repos/hub4j-test-org/test-readme/tags", + "blobs_url": "https://api.github.com/repos/hub4j-test-org/test-readme/git/blobs{/sha}", + "git_tags_url": "https://api.github.com/repos/hub4j-test-org/test-readme/git/tags{/sha}", + "git_refs_url": "https://api.github.com/repos/hub4j-test-org/test-readme/git/refs{/sha}", + "trees_url": "https://api.github.com/repos/hub4j-test-org/test-readme/git/trees{/sha}", + "statuses_url": "https://api.github.com/repos/hub4j-test-org/test-readme/statuses/{sha}", + "languages_url": "https://api.github.com/repos/hub4j-test-org/test-readme/languages", + "stargazers_url": "https://api.github.com/repos/hub4j-test-org/test-readme/stargazers", + "contributors_url": "https://api.github.com/repos/hub4j-test-org/test-readme/contributors", + "subscribers_url": "https://api.github.com/repos/hub4j-test-org/test-readme/subscribers", + "subscription_url": "https://api.github.com/repos/hub4j-test-org/test-readme/subscription", + "commits_url": "https://api.github.com/repos/hub4j-test-org/test-readme/commits{/sha}", + "git_commits_url": "https://api.github.com/repos/hub4j-test-org/test-readme/git/commits{/sha}", + "comments_url": "https://api.github.com/repos/hub4j-test-org/test-readme/comments{/number}", + "issue_comment_url": "https://api.github.com/repos/hub4j-test-org/test-readme/issues/comments{/number}", + "contents_url": "https://api.github.com/repos/hub4j-test-org/test-readme/contents/{+path}", + "compare_url": "https://api.github.com/repos/hub4j-test-org/test-readme/compare/{base}...{head}", + "merges_url": "https://api.github.com/repos/hub4j-test-org/test-readme/merges", + "archive_url": "https://api.github.com/repos/hub4j-test-org/test-readme/{archive_format}{/ref}", + "downloads_url": "https://api.github.com/repos/hub4j-test-org/test-readme/downloads", + "issues_url": "https://api.github.com/repos/hub4j-test-org/test-readme/issues{/number}", + "pulls_url": "https://api.github.com/repos/hub4j-test-org/test-readme/pulls{/number}", + "milestones_url": "https://api.github.com/repos/hub4j-test-org/test-readme/milestones{/number}", + "notifications_url": "https://api.github.com/repos/hub4j-test-org/test-readme/notifications{?since,all,participating}", + "labels_url": "https://api.github.com/repos/hub4j-test-org/test-readme/labels{/name}", + "releases_url": "https://api.github.com/repos/hub4j-test-org/test-readme/releases{/id}", + "deployments_url": "https://api.github.com/repos/hub4j-test-org/test-readme/deployments", + "created_at": "2015-02-15T14:24:54Z", + "updated_at": "2021-04-19T20:17:38Z", + "pushed_at": "2021-04-19T20:17:36Z", + "git_url": "git://github.com/hub4j-test-org/test-readme.git", + "ssh_url": "git@github.com:hub4j-test-org/test-readme.git", + "clone_url": "https://github.com/hub4j-test-org/test-readme.git", + "svn_url": "https://github.com/hub4j-test-org/test-readme", + "homepage": null, + "size": 0, + "stargazers_count": 0, + "watchers_count": 0, + "language": null, + "has_issues": true, + "has_projects": true, + "has_downloads": true, + "has_wiki": true, + "has_pages": false, + "forks_count": 0, + "mirror_url": null, + "archived": false, + "disabled": false, + "open_issues_count": 0, + "license": null, + "allow_forking": true, + "is_template": false, + "web_commit_signoff_required": false, + "topics": [], + "visibility": "public", + "forks": 0, + "open_issues": 0, + "watchers": 0, + "default_branch": "main", + "permissions": { + "admin": false, + "maintain": false, + "push": false, + "triage": false, + "pull": false + } + } + ] +} \ No newline at end of file diff --git a/src/test/resources/org/kohsuke/github/GHAuthenticatedAppInstallationTest/wiremock/testListRepositoriesTwoRepos/__files/orgs_hub4j-test-org_installation-2.json b/src/test/resources/org/kohsuke/github/GHAuthenticatedAppInstallationTest/wiremock/testListRepositoriesTwoRepos/__files/orgs_hub4j-test-org_installation-2.json new file mode 100644 index 0000000000..3b38788c91 --- /dev/null +++ b/src/test/resources/org/kohsuke/github/GHAuthenticatedAppInstallationTest/wiremock/testListRepositoriesTwoRepos/__files/orgs_hub4j-test-org_installation-2.json @@ -0,0 +1,40 @@ +{ + "id": 12129901, + "account": { + "login": "hub4j-test-org", + "id": 7544739, + "node_id": "MDEyOk9yZ2FuaXphdGlvbjc1NDQ3Mzk=", + "avatar_url": "https://avatars.githubusercontent.com/u/7544739?v=4", + "gravatar_id": "", + "url": "https://api.github.com/users/hub4j-test-org", + "html_url": "https://github.com/hub4j-test-org", + "followers_url": "https://api.github.com/users/hub4j-test-org/followers", + "following_url": "https://api.github.com/users/hub4j-test-org/following{/other_user}", + "gists_url": "https://api.github.com/users/hub4j-test-org/gists{/gist_id}", + "starred_url": "https://api.github.com/users/hub4j-test-org/starred{/owner}{/repo}", + "subscriptions_url": "https://api.github.com/users/hub4j-test-org/subscriptions", + "organizations_url": "https://api.github.com/users/hub4j-test-org/orgs", + "repos_url": "https://api.github.com/users/hub4j-test-org/repos", + "events_url": "https://api.github.com/users/hub4j-test-org/events{/privacy}", + "received_events_url": "https://api.github.com/users/hub4j-test-org/received_events", + "type": "Organization", + "site_admin": false + }, + "repository_selection": "selected", + "access_tokens_url": "https://api.github.com/app/installations/12129901/access_tokens", + "repositories_url": "https://api.github.com/installation/repositories", + "html_url": "https://github.com/organizations/hub4j-test-org/settings/installations/12129901", + "app_id": 82994, + "app_slug": "ghapi-test-app-1", + "target_id": 7544739, + "target_type": "Organization", + "permissions": {}, + "events": [], + "created_at": "2020-09-30T13:41:32.000Z", + "updated_at": "2022-09-21T13:14:03.000Z", + "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/GHAuthenticatedAppInstallationTest/wiremock/testListRepositoriesTwoRepos/mappings/app-1.json b/src/test/resources/org/kohsuke/github/GHAuthenticatedAppInstallationTest/wiremock/testListRepositoriesTwoRepos/mappings/app-1.json new file mode 100644 index 0000000000..489cbfcd12 --- /dev/null +++ b/src/test/resources/org/kohsuke/github/GHAuthenticatedAppInstallationTest/wiremock/testListRepositoriesTwoRepos/mappings/app-1.json @@ -0,0 +1,39 @@ +{ + "id": "d94214c6-a028-4265-848d-9f45e0e62ddf", + "name": "app", + "request": { + "url": "/app", + "method": "GET", + "headers": { + "Accept": { + "equalTo": "application/vnd.github.machine-man-preview+json" + } + } + }, + "response": { + "status": 200, + "bodyFileName": "app-1.json", + "headers": { + "Server": "GitHub.com", + "Date": "Wed, 21 Sep 2022 15:16:07 GMT", + "Content-Type": "application/json; charset=utf-8", + "Cache-Control": "public, max-age=60, s-maxage=60", + "Vary": [ + "Accept", + "Accept-Encoding, Accept, X-Requested-With" + ], + "ETag": "W/\"662c8ea184a852f605e0c94a9789fe43965f939e16e02ff0b3a8cc1043078a62\"", + "X-GitHub-Media-Type": "github.v3; param=machine-man-preview; format=json", + "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": "D261:5D3D:6D7FB78:6EF9066:632B2AB7" + } + }, + "uuid": "d94214c6-a028-4265-848d-9f45e0e62ddf", + "persistent": true, + "insertionIndex": 1 +} \ No newline at end of file diff --git a/src/test/resources/org/kohsuke/github/GHAuthenticatedAppInstallationTest/wiremock/testListRepositoriesTwoRepos/mappings/app_installations_12129901_access_tokens-3.json b/src/test/resources/org/kohsuke/github/GHAuthenticatedAppInstallationTest/wiremock/testListRepositoriesTwoRepos/mappings/app_installations_12129901_access_tokens-3.json new file mode 100644 index 0000000000..5089fdf364 --- /dev/null +++ b/src/test/resources/org/kohsuke/github/GHAuthenticatedAppInstallationTest/wiremock/testListRepositoriesTwoRepos/mappings/app_installations_12129901_access_tokens-3.json @@ -0,0 +1,46 @@ +{ + "id": "c5092131-2c36-4b47-afc4-935bf06557a3", + "name": "app_installations_12129901_access_tokens", + "request": { + "url": "/app/installations/12129901/access_tokens", + "method": "POST", + "headers": { + "Accept": { + "equalTo": "application/vnd.github.machine-man-preview+json" + } + }, + "bodyPatterns": [ + { + "equalToJson": "{}", + "ignoreArrayOrder": true, + "ignoreExtraElements": false + } + ] + }, + "response": { + "status": 201, + "body": "{\"token\":\"ghs_YoT4i7ItglAGBhRtnJqBKgGTjLrlBw48OogA\",\"expires_at\":\"2022-09-21T16:16:08Z\",\"permissions\":{\"contents\":\"read\",\"metadata\":\"read\"},\"repository_selection\":\"selected\"}", + "headers": { + "Server": "GitHub.com", + "Date": "Wed, 21 Sep 2022 15:16:08 GMT", + "Content-Type": "application/json; charset=utf-8", + "Cache-Control": "public, max-age=60, s-maxage=60", + "Vary": [ + "Accept", + "Accept-Encoding, Accept, X-Requested-With" + ], + "ETag": "\"0599246ac4273ded931a2d493c34e284a038afc82fe76d62d219c3f8a60ff313\"", + "X-GitHub-Media-Type": "github.v3; param=machine-man-preview; format=json", + "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": "E114:B08A:4BC15A1:4CF2905:632B2AB8" + } + }, + "uuid": "c5092131-2c36-4b47-afc4-935bf06557a3", + "persistent": true, + "insertionIndex": 3 +} \ No newline at end of file diff --git a/src/test/resources/org/kohsuke/github/GHAuthenticatedAppInstallationTest/wiremock/testListRepositoriesTwoRepos/mappings/installation_repositories-4.json b/src/test/resources/org/kohsuke/github/GHAuthenticatedAppInstallationTest/wiremock/testListRepositoriesTwoRepos/mappings/installation_repositories-4.json new file mode 100644 index 0000000000..25662ce71e --- /dev/null +++ b/src/test/resources/org/kohsuke/github/GHAuthenticatedAppInstallationTest/wiremock/testListRepositoriesTwoRepos/mappings/installation_repositories-4.json @@ -0,0 +1,44 @@ +{ + "id": "039aac93-94ba-4b47-840a-492765ce1fdc", + "name": "installation_repositories", + "request": { + "url": "/installation/repositories", + "method": "GET", + "headers": { + "Accept": { + "equalTo": "application/vnd.github.machine-man-preview+json" + } + } + }, + "response": { + "status": 200, + "bodyFileName": "installation_repositories-4.json", + "headers": { + "Server": "GitHub.com", + "Date": "Wed, 21 Sep 2022 15:16:08 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/\"ccc141b003bb4015c7772d4383f88726efaad307f31448ba35fac1a5ba0aaf23\"", + "X-GitHub-Media-Type": "github.v3; param=machine-man-preview; format=json", + "X-RateLimit-Limit": "5950", + "X-RateLimit-Remaining": "5949", + "X-RateLimit-Reset": "1663776968", + "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": "D13F:C712:6B899C5:6D0836C:632B2AB8" + } + }, + "uuid": "039aac93-94ba-4b47-840a-492765ce1fdc", + "persistent": true, + "insertionIndex": 4 +} \ No newline at end of file diff --git a/src/test/resources/org/kohsuke/github/GHAuthenticatedAppInstallationTest/wiremock/testListRepositoriesTwoRepos/mappings/orgs_hub4j-test-org_installation-2.json b/src/test/resources/org/kohsuke/github/GHAuthenticatedAppInstallationTest/wiremock/testListRepositoriesTwoRepos/mappings/orgs_hub4j-test-org_installation-2.json new file mode 100644 index 0000000000..b253a524b5 --- /dev/null +++ b/src/test/resources/org/kohsuke/github/GHAuthenticatedAppInstallationTest/wiremock/testListRepositoriesTwoRepos/mappings/orgs_hub4j-test-org_installation-2.json @@ -0,0 +1,39 @@ +{ + "id": "5b12b08d-1fe4-4a25-bd80-13beedffda3a", + "name": "orgs_hub4j-test-org_installation", + "request": { + "url": "/orgs/hub4j-test-org/installation", + "method": "GET", + "headers": { + "Accept": { + "equalTo": "application/vnd.github.machine-man-preview+json" + } + } + }, + "response": { + "status": 200, + "bodyFileName": "orgs_hub4j-test-org_installation-2.json", + "headers": { + "Server": "GitHub.com", + "Date": "Wed, 21 Sep 2022 15:16:07 GMT", + "Content-Type": "application/json; charset=utf-8", + "Cache-Control": "public, max-age=60, s-maxage=60", + "Vary": [ + "Accept", + "Accept-Encoding, Accept, X-Requested-With" + ], + "ETag": "W/\"ef60cfb42fb3e7e8e8e98142d655b44c0ed888d1ecad08ad075ff4318aca1494\"", + "X-GitHub-Media-Type": "github.v3; param=machine-man-preview; format=json", + "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": "C4FA:CC72:2B91B2B:2C4999A:632B2AB7" + } + }, + "uuid": "5b12b08d-1fe4-4a25-bd80-13beedffda3a", + "persistent": true, + "insertionIndex": 2 +} \ No newline at end of file