Skip to content

Commit

Permalink
🐛 events, test w/ split organizations
Browse files Browse the repository at this point in the history
  • Loading branch information
ebullient committed Jun 15, 2024
1 parent 61f2b9b commit 1429748
Show file tree
Hide file tree
Showing 17 changed files with 472 additions and 406 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package org.commonhaus.automation.github.discovery;

import org.kohsuke.github.GitHub;

import io.smallrye.graphql.client.dynamic.api.DynamicGraphQLClient;

public record PostInitialDiscoveryEvent(
long installationId,
GitHub github,
DynamicGraphQLClient graphQLClient) {
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ public class RepositoryDiscovery {
@Inject
Event<RepositoryDiscoveryEvent> repositoryDiscoveryEvent;

@Inject
Event<PostInitialDiscoveryEvent> postDiscoveryEvent;

private ContextService ctx;

// discoverRepositories is/was being called twice. Avoid double discovery
Expand All @@ -67,11 +70,14 @@ void discoverRepositories(@Observes StartupEvent ev) {
DynamicGraphQLClient graphQLClient = gitHubService.getInstallationGraphQLClient(ghiId);
GHAuthenticatedAppInstallation ghai = github.getInstallation();

Log.debugf("[%s] Fire initial discovery events", ghiId);
for (GHRepository repo : ghai.listRepositories()) {
repositoryDiscoveryEvent.fire(new RepositoryDiscoveryEvent(
DiscoveryAction.ADDED, github, graphQLClient, ghiId,
repo, fetchConfigFile(repo)));
repo, fetchConfigFile(repo), true));
}
Log.debugf("[%s] PostInitialDiscoveryEvent", ghiId);
postDiscoveryEvent.fire(new PostInitialDiscoveryEvent(ghiId, github, graphQLClient));
}
} catch (GHIOException e) {
ctx.logAndSendEmail("discoverRepositories", "Error making GH Request", e, null);
Expand Down Expand Up @@ -114,14 +120,14 @@ void onInstallationChange(@RawEvent(event = "installation") GitHubEvent gitHubEv
for (GHRepository repo : repositories) {
repositoryDiscoveryEvent.fire(new RepositoryDiscoveryEvent(
DiscoveryAction.INSTALL_ADDED, github, graphQLClient, installationId,
repo, fetchConfigFile(repo)));
repo, fetchConfigFile(repo), false));
}
}
case "deleted", "suspend" -> {
for (GHRepository repo : repositories) {
repositoryDiscoveryEvent.fire(new RepositoryDiscoveryEvent(
DiscoveryAction.INSTALL_REMOVED, github, graphQLClient, installationId,
repo, null));
repo, null, false));
}
}
default -> {
Expand Down Expand Up @@ -155,13 +161,13 @@ protected void handleRepositoryChanges(GitHub github, DynamicGraphQLClient graph
for (GHRepository repo : added) {
repositoryDiscoveryEvent.fire(new RepositoryDiscoveryEvent(
DiscoveryAction.ADDED, github, graphQLClient, installationId,
repo, fetchConfigFile(repo)));
repo, fetchConfigFile(repo), false));
}

for (GHRepository repo : removed) {
repositoryDiscoveryEvent.fire(new RepositoryDiscoveryEvent(
DiscoveryAction.REMOVED, github, graphQLClient, installationId,
repo, null));
repo, null, false));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ public record RepositoryDiscoveryEvent(
DynamicGraphQLClient graphQLClient,
long installationId,
GHRepository repository,
Optional<?> repoConfig) {
Optional<?> repoConfig,
boolean bootstrap) {

public boolean added() {
return action.added();
Expand Down
Loading

0 comments on commit 1429748

Please sign in to comment.