Skip to content

Commit e20a7d2

Browse files
committed
fix: proper green check
1 parent beb79f0 commit e20a7d2

1 file changed

Lines changed: 32 additions & 5 deletions

File tree

src/app.ts

Lines changed: 32 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,39 @@ async function isPRGreen(octokit: Octokit, owner: string, repo: string, pullNumb
2424
ref: pullRequest.head.sha,
2525
});
2626

27-
const failedChecks = checkRunsData.check_runs
28-
.filter((run) => run.status === 'completed' && run.conclusion !== 'success')
29-
.map((run) => run.name);
27+
// Group check runs by name and keep only the latest run for each check
28+
const latestCheckRuns = checkRunsData.check_runs.reduce<Record<string, (typeof checkRunsData.check_runs)[number]>>(
29+
(latest, run) => {
30+
// If we haven't seen this check before or this run is newer, update
31+
if (!latest[run.name] || new Date(run.completed_at!) > new Date(latest[run.name]!.completed_at!)) {
32+
latest[run.name] = run;
33+
}
34+
35+
return latest;
36+
},
37+
{},
38+
);
39+
40+
const failedChecks = Object.values(latestCheckRuns).filter(
41+
(run) =>
42+
run.status === 'completed' &&
43+
run.conclusion !== 'success' &&
44+
run.conclusion !== 'neutral' &&
45+
// This is often our label CI
46+
run.conclusion !== 'skipped',
47+
);
48+
49+
const isGreen = statusData.state === 'success' && failedChecks.length === 0;
50+
logger.debug(
51+
{
52+
isGreen,
53+
status: statusData.state,
54+
failedChecks,
55+
},
56+
'PR green check',
57+
);
3058

31-
return statusData.state === 'success' && failedChecks.length === 0;
59+
return isGreen;
3260
}
3361

3462
export function getApp(env: Env) {
@@ -85,7 +113,6 @@ export function getApp(env: Env) {
85113
data.payload.issue.number,
86114
))
87115
) {
88-
logger.debug('Pull request is not green');
89116
return;
90117
}
91118

0 commit comments

Comments
 (0)