Skip to content

Commit e817eb8

Browse files
authored
ci: Bind Codex findings to review request
1 parent 11f88af commit e817eb8

1 file changed

Lines changed: 56 additions & 15 deletions

File tree

‎.github/workflows/codex-review-gate.yml‎

Lines changed: 56 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -401,21 +401,6 @@ jobs:
401401
terminal.push({ at: createdAt, kind: 'approve', findingCount: 0 });
402402
}
403403
404-
if (allowApproval && requestBoundApproval && requestCommentId) {
405-
for (const reaction of requestReactions) {
406-
if (!isCodex(reaction.user?.login)) continue;
407-
if (reaction.content !== '+1') continue;
408-
const createdAt = asDate(reaction.created_at);
409-
if (!createdAt || createdAt < resultFloor) continue;
410-
terminal.push({ at: createdAt, kind: 'approve', findingCount: 0 });
411-
}
412-
}
413-
414-
terminal.sort((a, b) => {
415-
if (a.kind !== b.kind) return a.kind === 'findings' ? -1 : 1;
416-
return b.at - a.at;
417-
});
418-
419404
const quotas = issueComments
420405
.filter((comment) => {
421406
if (!isCodex(comment.user?.login)) return false;
@@ -433,6 +418,62 @@ jobs:
433418
}))
434419
.sort((a, b) => b.at - a.at);
435420
421+
if (requestBoundApproval && !requestCommentId) {
422+
return {
423+
terminal: null,
424+
quota: null,
425+
startedAt,
426+
};
427+
}
428+
429+
if (requestBoundApproval && requestCommentId) {
430+
const codexReactions = requestReactions.filter((reaction) =>
431+
isCodex(reaction.user?.login),
432+
);
433+
const approvalReaction = codexReactions
434+
.filter((reaction) => reaction.content === '+1')
435+
.map((reaction) => ({
436+
at: asDate(reaction.created_at),
437+
kind: 'approve',
438+
findingCount: 0,
439+
}))
440+
.filter((reaction) => reaction.at && reaction.at >= resultFloor)
441+
.sort((a, b) => b.at - a.at)[0];
442+
const reviewInProgress = codexReactions.some(
443+
(reaction) => reaction.content === 'eyes',
444+
);
445+
446+
if (allowApproval && approvalReaction) {
447+
return {
448+
terminal: approvalReaction,
449+
quota: quotas[0] || null,
450+
startedAt,
451+
};
452+
}
453+
454+
if (reviewInProgress || quotas.length > 0) {
455+
return {
456+
terminal: null,
457+
quota: quotas[0] || null,
458+
startedAt,
459+
};
460+
}
461+
462+
const finding = terminal
463+
.filter((item) => item.kind === 'findings')
464+
.sort((a, b) => b.at - a.at)[0];
465+
return {
466+
terminal: finding || null,
467+
quota: null,
468+
startedAt,
469+
};
470+
}
471+
472+
terminal.sort((a, b) => {
473+
if (a.kind !== b.kind) return a.kind === 'findings' ? -1 : 1;
474+
return b.at - a.at;
475+
});
476+
436477
return {
437478
terminal: terminal[0] || null,
438479
quota: quotas[0] || null,

0 commit comments

Comments
 (0)