-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: use commit statuses for base image update check (#217)
- Loading branch information
1 parent
6fc7723
commit deb92d8
Showing
2 changed files
with
126 additions
and
156 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,37 +1,29 @@ | ||
import { getOctokit } from './getOctokit'; | ||
import { RestEndpointMethodTypes } from '@octokit/rest'; | ||
import { groupBy, isEqual, sortBy } from 'lodash'; | ||
import { VISUAL_REGRESSION_CONTEXT } from 'shared'; | ||
|
||
type CheckRunConclusion = | ||
RestEndpointMethodTypes['checks']['listForRef']['response']['data']['check_runs'][number]['conclusion']; | ||
|
||
const allowedConclusions: CheckRunConclusion[] = ['success', 'skipped']; | ||
|
||
export const allNonVisualChecksHavePassed = async ( | ||
owner: string, | ||
repo: string, | ||
sha: string | ||
): Promise<boolean> => { | ||
const octokit = getOctokit(owner, repo); | ||
|
||
const { data } = await octokit.rest.checks.listForRef({ | ||
const { data } = await octokit.rest.repos.listCommitStatusesForRef({ | ||
owner, | ||
repo, | ||
ref: sha, | ||
}); | ||
const nonVisualChecks = data.check_runs.filter( | ||
({ name }) => name !== VISUAL_REGRESSION_CONTEXT | ||
const nonVisualStatuses = data.filter( | ||
({ context }) => context !== VISUAL_REGRESSION_CONTEXT | ||
); | ||
const groupedChecks = groupBy(nonVisualChecks, 'name'); | ||
const mostRecentChecks = nonVisualChecks.filter(check => { | ||
const checksSortedByDescTime = sortBy( | ||
groupedChecks[check.name], | ||
'completed_at' | ||
const groupedNonVisualStatuses = groupBy(nonVisualStatuses, 'context'); | ||
const mostRecentNonVisualStatuses = nonVisualStatuses.filter(status => { | ||
const contextsSortedByDescTime = sortBy( | ||
groupedNonVisualStatuses[status.context], | ||
'created_at' | ||
).reverse(); | ||
return isEqual(check, checksSortedByDescTime[0]); | ||
return isEqual(status, contextsSortedByDescTime.find(Boolean)); | ||
}); | ||
return mostRecentChecks.every(({ conclusion }) => | ||
allowedConclusions.includes(conclusion) | ||
); | ||
return mostRecentNonVisualStatuses.every(({ state }) => state === 'success'); | ||
}; |
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