Skip to content

Commit 97a1fc1

Browse files
feat: get Installation identified by its installation id (#151)
* feat: get Installation identified by its installation id * chore: change URL string --------- Co-authored-by: Felix Seifert <[email protected]>
1 parent 24b73da commit 97a1fc1

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed

src/main/java/com/spotify/github/v3/clients/GithubAppClient.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
/** Apps API client */
3535
public class GithubAppClient {
3636

37+
private static final String GET_INSTALLATION_BY_ID_URL = "/app/installations/%s";
3738
private static final String GET_ACCESS_TOKEN_URL = "/app/installations/%s/access_tokens";
3839
private static final String GET_INSTALLATIONS_URL = "/app/installations?per_page=100";
3940
private static final String GET_INSTALLATION_REPO_URL = "/repos/%s/%s/installation";
@@ -85,6 +86,16 @@ public CompletableFuture<Installation> getInstallation() {
8586
return maybeRepo.map(this::getRepoInstallation).orElseGet(this::getOrgInstallation);
8687
}
8788

89+
/**
90+
* Get Installation identified by its installation id
91+
*
92+
* @return an Installation
93+
*/
94+
public CompletableFuture<Installation> getInstallation(final Integer installationId) {
95+
return github.request(
96+
String.format(GET_INSTALLATION_BY_ID_URL, installationId), Installation.class);
97+
}
98+
8899
/**
89100
* Get an installation of a repo
90101
* @return an Installation

src/test/java/com/spotify/github/v3/clients/GithubAppClientTest.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,4 +144,20 @@ public void getInstallation() throws Exception {
144144
RecordedRequest recordedRequest = mockServer.takeRequest(1, TimeUnit.MILLISECONDS);
145145
assertThat(recordedRequest.getRequestUrl().encodedPath(), is("/repos/owner/repo/installation"));
146146
}
147+
148+
@Test
149+
public void getInstallationByInstallationId() throws Exception {
150+
mockServer.enqueue(
151+
new MockResponse()
152+
.setResponseCode(200)
153+
.setBody(FixtureHelper.loadFixture("githubapp/installation.json")));
154+
155+
Installation installation = client.getInstallation(1234).join();
156+
157+
assertThat(installation.id(), is(1));
158+
assertThat(installation.account().login(), is("github"));
159+
160+
RecordedRequest recordedRequest = mockServer.takeRequest(1, TimeUnit.MILLISECONDS);
161+
assertThat(recordedRequest.getRequestUrl().encodedPath(), is("/app/installations/1234"));
162+
}
147163
}

0 commit comments

Comments
 (0)