From 5d130a96f7bd29a489f2381d51abdfabb2814447 Mon Sep 17 00:00:00 2001 From: Michael Wurster Date: Thu, 28 Dec 2023 08:19:38 +0100 Subject: [PATCH 1/2] feat: get Installation identified by its installation id --- .../github/v3/clients/GithubAppClient.java | 11 +++++++++++ .../github/v3/clients/GithubAppClientTest.java | 16 ++++++++++++++++ 2 files changed, 27 insertions(+) diff --git a/src/main/java/com/spotify/github/v3/clients/GithubAppClient.java b/src/main/java/com/spotify/github/v3/clients/GithubAppClient.java index 0ad677d2..3cc38017 100644 --- a/src/main/java/com/spotify/github/v3/clients/GithubAppClient.java +++ b/src/main/java/com/spotify/github/v3/clients/GithubAppClient.java @@ -34,6 +34,7 @@ /** Apps API client */ public class GithubAppClient { + private static final String GET_INSTALLATION_URL = "/app/installations/%s"; private static final String GET_ACCESS_TOKEN_URL = "/app/installations/%s/access_tokens"; private static final String GET_INSTALLATIONS_URL = "/app/installations?per_page=100"; private static final String GET_INSTALLATION_REPO_URL = "/repos/%s/%s/installation"; @@ -85,6 +86,16 @@ public CompletableFuture getInstallation() { return maybeRepo.map(this::getRepoInstallation).orElseGet(this::getOrgInstallation); } + /** + * Get Installation identified by its installation id + * + * @return an Installation + */ + public CompletableFuture getInstallation(final Integer installationId) { + return github.request( + String.format(GET_INSTALLATION_URL, installationId), Installation.class); + } + /** * Get an installation of a repo * @return an Installation diff --git a/src/test/java/com/spotify/github/v3/clients/GithubAppClientTest.java b/src/test/java/com/spotify/github/v3/clients/GithubAppClientTest.java index a26711dc..62e92757 100644 --- a/src/test/java/com/spotify/github/v3/clients/GithubAppClientTest.java +++ b/src/test/java/com/spotify/github/v3/clients/GithubAppClientTest.java @@ -144,4 +144,20 @@ public void getInstallation() throws Exception { RecordedRequest recordedRequest = mockServer.takeRequest(1, TimeUnit.MILLISECONDS); assertThat(recordedRequest.getRequestUrl().encodedPath(), is("/repos/owner/repo/installation")); } + + @Test + public void getInstallationByInstallationId() throws Exception { + mockServer.enqueue( + new MockResponse() + .setResponseCode(200) + .setBody(FixtureHelper.loadFixture("githubapp/installation.json"))); + + Installation installation = client.getInstallation(1234).join(); + + assertThat(installation.id(), is(1)); + assertThat(installation.account().login(), is("github")); + + RecordedRequest recordedRequest = mockServer.takeRequest(1, TimeUnit.MILLISECONDS); + assertThat(recordedRequest.getRequestUrl().encodedPath(), is("/app/installations/1234")); + } } From 331bf5cc39804c5b49f925fcf623abe3d9bf9a9d Mon Sep 17 00:00:00 2001 From: Felix Seifert Date: Thu, 28 Dec 2023 10:13:33 +0100 Subject: [PATCH 2/2] chore: change URL string --- .../java/com/spotify/github/v3/clients/GithubAppClient.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/spotify/github/v3/clients/GithubAppClient.java b/src/main/java/com/spotify/github/v3/clients/GithubAppClient.java index 3cc38017..9198fc60 100644 --- a/src/main/java/com/spotify/github/v3/clients/GithubAppClient.java +++ b/src/main/java/com/spotify/github/v3/clients/GithubAppClient.java @@ -34,7 +34,7 @@ /** Apps API client */ public class GithubAppClient { - private static final String GET_INSTALLATION_URL = "/app/installations/%s"; + private static final String GET_INSTALLATION_BY_ID_URL = "/app/installations/%s"; private static final String GET_ACCESS_TOKEN_URL = "/app/installations/%s/access_tokens"; private static final String GET_INSTALLATIONS_URL = "/app/installations?per_page=100"; private static final String GET_INSTALLATION_REPO_URL = "/repos/%s/%s/installation"; @@ -93,7 +93,7 @@ public CompletableFuture getInstallation() { */ public CompletableFuture getInstallation(final Integer installationId) { return github.request( - String.format(GET_INSTALLATION_URL, installationId), Installation.class); + String.format(GET_INSTALLATION_BY_ID_URL, installationId), Installation.class); } /**