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..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,6 +34,7 @@ /** Apps API client */ public class GithubAppClient { + 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"; @@ -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_BY_ID_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")); + } }