-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #361 from yrodiere/list-installs
Expose the application GitHub client so that apps can list their own installations
- Loading branch information
Showing
19 changed files
with
407 additions
and
59 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 27 additions & 0 deletions
27
.../src/test/java/io/quarkiverse/githubapp/deployment/GitHubClientProviderInjectionTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package io.quarkiverse.githubapp.deployment; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
import org.jboss.shrinkwrap.api.ShrinkWrap; | ||
import org.jboss.shrinkwrap.api.spec.JavaArchive; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.RegisterExtension; | ||
|
||
import io.quarkiverse.githubapp.GitHubClientProvider; | ||
import io.quarkiverse.githubapp.runtime.github.GitHubService; | ||
import io.quarkus.arc.Arc; | ||
import io.quarkus.test.QuarkusUnitTest; | ||
|
||
public class GitHubClientProviderInjectionTest { | ||
|
||
@RegisterExtension | ||
static final QuarkusUnitTest config = new QuarkusUnitTest() | ||
.setArchiveProducer(() -> ShrinkWrap.create(JavaArchive.class)) | ||
.withConfigurationResource("application.properties"); | ||
|
||
@Test | ||
public void test() { | ||
assertThat(Arc.container().instance(GitHubClientProvider.class).get()) | ||
.isInstanceOf(GitHubService.class); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
...ework/src/main/java/io/quarkiverse/githubapp/it/testingframework/BackgroundProcessor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package io.quarkiverse.githubapp.it.testingframework; | ||
|
||
import java.io.IOException; | ||
|
||
import javax.enterprise.context.ApplicationScoped; | ||
import javax.inject.Inject; | ||
|
||
import io.quarkiverse.githubapp.GitHubClientProvider; | ||
|
||
@ApplicationScoped | ||
public class BackgroundProcessor { | ||
|
||
public static Behavior behavior; | ||
|
||
@Inject | ||
GitHubClientProvider clientProvider; | ||
|
||
public void process() throws IOException { | ||
behavior.execute(clientProvider); | ||
} | ||
|
||
public interface Behavior { | ||
void execute(GitHubClientProvider clientProvider) throws IOException; | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
...ting-framework/src/test/java/io/quarkiverse/githubapp/it/testingframework/MockHelper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package io.quarkiverse.githubapp.it.testingframework; | ||
|
||
import static org.mockito.Mockito.mock; | ||
import static org.mockito.Mockito.when; | ||
|
||
import java.util.Iterator; | ||
import java.util.List; | ||
|
||
import org.kohsuke.github.PagedIterator; | ||
import org.kohsuke.github.PagedSearchIterable; | ||
|
||
class MockHelper { | ||
|
||
@SafeVarargs | ||
@SuppressWarnings("unchecked") | ||
public static <T> PagedSearchIterable<T> mockPagedIterable(T... contentMocks) { | ||
PagedSearchIterable<T> iterableMock = mock(PagedSearchIterable.class); | ||
when(iterableMock.iterator()).thenAnswer(ignored -> { | ||
PagedIterator<T> iteratorMock = mock(PagedIterator.class); | ||
Iterator<T> actualIterator = List.of(contentMocks).iterator(); | ||
when(iteratorMock.next()).thenAnswer(ignored2 -> actualIterator.next()); | ||
when(iteratorMock.hasNext()).thenAnswer(ignored2 -> actualIterator.hasNext()); | ||
return iteratorMock; | ||
}); | ||
return iterableMock; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
71 changes: 71 additions & 0 deletions
71
runtime/src/main/java/io/quarkiverse/githubapp/GitHubClientProvider.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
package io.quarkiverse.githubapp; | ||
|
||
import org.kohsuke.github.GHApp; | ||
import org.kohsuke.github.GitHub; | ||
|
||
import io.smallrye.graphql.client.dynamic.api.DynamicGraphQLClient; | ||
|
||
/** | ||
* A provider of {@link org.kohsuke.github.GitHub GitHub clients} for the GitHub app. | ||
* <p> | ||
* Inject as a CDI bean. | ||
* <p> | ||
* <strong>NOTE:</strong> You generally will not need this bean when processing events, | ||
* as clients can be automatically injected into event listener methods, | ||
* simply by adding a parameter of type {@link GitHub} or {@link DynamicGraphQLClient} to the listener method. | ||
* This provider is mostly useful for non-event use cases (e.g. cron jobs). | ||
*/ | ||
public interface GitHubClientProvider { | ||
|
||
/** | ||
* Gets the {@link GitHub GitHub client} for the application: | ||
* it can be used without any installation, but has very little access rights (almost as little as an anonymous client). | ||
* <p> | ||
* The client will remain functional a few minutes at best, | ||
* so you should discard it as soon as possible and retrieve another one when necessary. | ||
* <p> | ||
* <strong>NOTE:</strong> You generally will not need this method when processing events, as the more powerful | ||
* {@link #getInstallationClient(long) installation client} gets automatically injected into event listeners. | ||
* This method can still be useful for non-event use cases (e.g. cron jobs), | ||
* to {@link GitHub#getApp() retrieve information about the application}, | ||
* in particular {@link GHApp#listInstallations() list application installations}. | ||
* | ||
* @return The application client. | ||
*/ | ||
GitHub getApplicationClient(); | ||
|
||
/** | ||
* Gets the {@link GitHub GitHub client} for a given application installation. | ||
* <p> | ||
* The client will remain functional a few minutes at best, | ||
* so you should discard it as soon as possible and retrieve another one when necessary. | ||
* <p> | ||
* <strong>NOTE:</strong> You generally will not need this method when processing events, | ||
* as this client can be automatically injected into event listener listener methods, | ||
* simply by adding a parameter of type {@link GitHub} to the method. | ||
* This method can still be useful for non-event use cases (e.g. cron jobs), | ||
* to retrieve installation clients after having {@link GHApp#listInstallations() list application installations} | ||
* from the {@link #getApplicationClient() application client}. | ||
* | ||
* @return The client for the given installation. | ||
*/ | ||
GitHub getInstallationClient(long installationId); | ||
|
||
/** | ||
* Gets the {@link DynamicGraphQLClient GraphQL GitHub client} for a given application installation. | ||
* <p> | ||
* The client will remain functional a few minutes at best, | ||
* so you should discard it as soon as possible and retrieve another one when necessary. | ||
* <p> | ||
* <strong>NOTE:</strong> You generally will not need this method when processing events, | ||
* as this client can be automatically injected into event listener methods, | ||
* simply by adding a parameter of type {@link DynamicGraphQLClient} to the listener method. | ||
* This method can still be useful for non-event use cases (e.g. cron jobs), | ||
* to retrieve installation clients after having {@link GHApp#listInstallations() list application installations} | ||
* from the {@link #getApplicationClient() application client}. | ||
* | ||
* @return The client for the given installation. | ||
*/ | ||
DynamicGraphQLClient getInstallationGraphQLClient(long installationId); | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.