Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions src/main/java/com/spotify/github/v3/clients/GithubAppClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -85,6 +86,16 @@ public CompletableFuture<Installation> getInstallation() {
return maybeRepo.map(this::getRepoInstallation).orElseGet(this::getOrgInstallation);
}

/**
* Get Installation identified by its installation id
*
* @return an Installation
*/
public CompletableFuture<Installation> 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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"));
}
}