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
13 changes: 13 additions & 0 deletions src/main/java/com/spotify/github/v3/clients/GitHubClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,19 @@ static String responseBodyUnchecked(final Response response) {
}
}

public GitHubClient withScopeForInstallationId(final int installationId) {
if (Optional.ofNullable(privateKey).isEmpty()) {
throw new RuntimeException("Installation ID scoped client needs a private key");
}
return new GitHubClient(
client,
baseUrl,
null,
privateKey,
appId,
installationId);
}

public GitHubClient withTracer(final Tracer tracer) {
this.tracer = tracer;
return this;
Expand Down
16 changes: 16 additions & 0 deletions src/test/java/com/spotify/github/v3/clients/GitHubClientTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,11 @@
import com.spotify.github.v3.exceptions.RequestNotOkException;
import com.spotify.github.v3.repos.CommitItem;
import com.spotify.github.v3.repos.RepositoryInvitation;

import java.io.File;
import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.Optional;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;
Expand Down Expand Up @@ -70,6 +73,19 @@ public void setUp() {
github = GitHubClient.create(client, URI.create("http://bogus"), "token");
}

@Test
public void withScopedInstallationIdShouldFailWhenMissingPrivateKey() {
assertThrows(RuntimeException.class, () -> github.withScopeForInstallationId(1));
}

@Test
public void testWithScopedInstallationId() throws URISyntaxException {
GitHubClient org = GitHubClient.create(new URI("http://apa.bepa.cepa"), "some_key_content".getBytes(), null, null);
GitHubClient scoped = org.withScopeForInstallationId(1);
Assertions.assertTrue(scoped.getPrivateKey().isPresent());
Assertions.assertEquals(org.getPrivateKey().get(), scoped.getPrivateKey().get());
}

@Test
public void testSearchIssue() throws Throwable {

Expand Down