-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use Step Functions for crawler orchestration
Before this change all crawler orchestration happened in-Lambda. Moving to step functions is useful for a few reasons: 1 - Soonish I'd like to add the ability to add public repos, and updating those can also use this crawler logic 2 - Going to have to deal with GitHub rate limiting and retries at some point - Step Functions is a good use for that 3 - Async data loading is a good example of Step Functions anyway, and it's good to have Step Functions in Cicada somewhere from an example point of view
- Loading branch information
1 parent
9b3bddf
commit a6c24ba
Showing
29 changed files
with
745 additions
and
453 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
This file was deleted.
Oops, something went wrong.
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,12 @@ | ||
import { processRawInstallation } from '../githubInstallation' | ||
import { AppState } from '../../../environment/AppState' | ||
import { removeNullAndUndefined } from '../../../util/collections' | ||
import { GithubInstallation } from '../../types/GithubInstallation' | ||
|
||
export async function crawlInstallations(appState: AppState): Promise<GithubInstallation[]> { | ||
const installations = await appState.githubClient.listInstallations() | ||
|
||
return removeNullAndUndefined( | ||
await Promise.all(installations.map(async (raw) => processRawInstallation(appState, raw))) | ||
) | ||
} |
44 changes: 7 additions & 37 deletions
44
...github/crawler/githubRepositoryCrawler.ts → src/app/domain/github/crawler/crawlPushes.ts
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import { AppState } from '../../../environment/AppState' | ||
import { GithubInstallation } from '../../types/GithubInstallation' | ||
import { GithubInstallationClient } from '../../../outboundInterfaces/githubInstallationClient' | ||
import { processRawRepositories } from '../githubRepository' | ||
import { ORGANIZATION_ACCOUNT_TYPE, USER_ACCOUNT_TYPE } from '../../types/githubCommonTypes' | ||
|
||
export async function crawlRepositories(appState: AppState, installation: GithubInstallation) { | ||
const githubClient = appState.githubClient.clientForInstallation(installation.installationId) | ||
const latestRawRepositories = await readRawRepositories(installation, githubClient) | ||
return await processRawRepositories(appState, latestRawRepositories) | ||
} | ||
|
||
async function readRawRepositories(installation: GithubInstallation, githubClient: GithubInstallationClient) { | ||
if (installation.accountType === ORGANIZATION_ACCOUNT_TYPE) { | ||
return await githubClient.listOrganizationRepositories(installation.accountLogin) | ||
} else if (installation.accountType === USER_ACCOUNT_TYPE) { | ||
return await githubClient.listInstallationRepositories() | ||
} else { | ||
throw new Error(`Unknown installation account type: ${installation.accountType}`) | ||
} | ||
} |
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,23 @@ | ||
import { AppState } from '../../../environment/AppState' | ||
import { GithubRepository } from '../../types/GithubRepository' | ||
import { dateTimeAddDays } from '../../../util/dateAndTime' | ||
import { processRawRunEvents } from '../githubWorkflowRunEvent' | ||
import { GithubInstallation } from '../../types/GithubInstallation' | ||
|
||
export async function crawlWorkflowRunEvents( | ||
appState: AppState, | ||
// the owner ID on repo isn't sufficient when we are crawling public repos from other accounts | ||
installation: GithubInstallation, | ||
repo: GithubRepository, | ||
lookbackDays: number | ||
) { | ||
const githubClient = appState.githubClient.clientForInstallation(installation.installationId) | ||
const startTime = `${dateTimeAddDays(appState.clock.now(), -1 * lookbackDays).toISOString()}` | ||
|
||
const recentRunEvents = await githubClient.listWorkflowRunsForRepo( | ||
repo.ownerName, | ||
repo.name, | ||
`>${startTime}` | ||
) | ||
await processRawRunEvents(appState, recentRunEvents, false) | ||
} |
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,23 @@ | ||
import { AppState } from '../../../environment/AppState' | ||
import { GithubInstallation } from '../../types/GithubInstallation' | ||
import { GithubInstallationClient } from '../../../outboundInterfaces/githubInstallationClient' | ||
import { processRawUsers } from '../githubUser' | ||
import { ORGANIZATION_ACCOUNT_TYPE, USER_ACCOUNT_TYPE } from '../../types/githubCommonTypes' | ||
|
||
export async function crawlUsers(appState: AppState, installation: GithubInstallation) { | ||
const latestRawUsers = await readRawUsers( | ||
installation, | ||
appState.githubClient.clientForInstallation(installation.installationId) | ||
) | ||
await processRawUsers(appState, latestRawUsers, installation) | ||
} | ||
|
||
async function readRawUsers(installation: GithubInstallation, githubClient: GithubInstallationClient) { | ||
if (installation.accountType === ORGANIZATION_ACCOUNT_TYPE) { | ||
return await githubClient.listOrganizationMembers(installation.accountLogin) | ||
} else if (installation.accountType === USER_ACCOUNT_TYPE) { | ||
return [await githubClient.getUser(installation.accountLogin)] | ||
} else { | ||
throw new Error(`Unknown installation account type: ${installation.accountType}`) | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
56 changes: 0 additions & 56 deletions
56
src/app/domain/github/crawler/githubInstallationCrawler.ts
This file was deleted.
Oops, something went wrong.
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
15 changes: 8 additions & 7 deletions
15
src/app/domain/github/webhookProcessor/processors/githubWebhookInstallationProcessor.ts
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 |
---|---|---|
@@ -1,21 +1,22 @@ | ||
import { fromRawGithubInstallation } from '../../../types/GithubInstallation' | ||
import { RawGithubInstallation } from '../../../types/rawGithub/RawGithubInstallation' | ||
import { processInstallation } from '../../githubInstallation' | ||
import { AppState } from '../../../../environment/AppState' | ||
import { WebhookProcessor } from '../WebhookProcessor' | ||
import { processInstallation } from '../../githubInstallation' | ||
import { sendToEventBridge } from '../../../../outboundInterfaces/eventBridgeBus' | ||
import { EVENTBRIDGE_DETAIL_TYPES } from '../../../../../multipleContexts/eventBridge' | ||
|
||
export const githubWebhookInstallationProcessor: WebhookProcessor = async ( | ||
appState: AppState, | ||
body: string | ||
): Promise<void> => { | ||
// TOEventually - need to differentiate sub-types of installation - e.g. deleted | ||
// TOEventually - type check, e.g. with AJV | ||
const parsed = fromRawGithubInstallation(JSON.parse(body).installation as RawGithubInstallation) | ||
if (!parsed) { | ||
const installation = fromRawGithubInstallation(JSON.parse(body).installation as RawGithubInstallation) | ||
if (!installation) { | ||
return | ||
} | ||
await processInstallation(appState, parsed, { | ||
crawlChildObjects: 'ifChanged', | ||
lookbackDays: 90 | ||
}) | ||
|
||
await processInstallation(appState, installation) | ||
await sendToEventBridge(appState, EVENTBRIDGE_DETAIL_TYPES.INSTALLATION_UPDATED, installation) | ||
} |
Oops, something went wrong.