Skip to content

Commit 588cdcb

Browse files
committed
ci: harden Codex inbox migration
1 parent ce1a9e2 commit 588cdcb

1 file changed

Lines changed: 25 additions & 3 deletions

File tree

.github/scripts/handle-codex-pr-comments.mjs

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -392,17 +392,39 @@ async function findInboxIssues() {
392392
}
393393

394394
function isManagedInboxIssue(issue) {
395+
return isLabeledInboxIssue(issue) || isMigratableInboxIssue(issue);
396+
}
397+
398+
function isLabeledInboxIssue(issue) {
399+
return hasInboxIdentity(issue) && issue.labels?.some((label) => label.name === inboxIssueLabel);
400+
}
401+
402+
function isMigratableInboxIssue(issue) {
403+
return hasInboxIdentity(issue) && isTrustedInboxIssueCreator(issue);
404+
}
405+
406+
function hasInboxIdentity(issue) {
395407
return issue.title === inboxIssueTitle && issue.body?.includes(inboxMarker);
396408
}
397409

410+
function isTrustedInboxIssueCreator(issue) {
411+
return ["app/github-actions", "github-actions[bot]"].includes(issue.user?.login);
412+
}
413+
398414
function chooseCanonicalInboxIssue(issues) {
415+
const openIssues = issues.filter((issue) => issue.state === "open");
416+
399417
return (
400-
issues
401-
.filter((issue) => issue.state === "open")
402-
.sort((left, right) => new Date(right.updated_at) - new Date(left.updated_at))[0] ?? null
418+
sortIssuesByUpdatedDesc(openIssues.filter(isLabeledInboxIssue))[0] ??
419+
sortIssuesByUpdatedDesc(openIssues.filter(isMigratableInboxIssue))[0] ??
420+
null
403421
);
404422
}
405423

424+
function sortIssuesByUpdatedDesc(issues) {
425+
return [...issues].sort((left, right) => new Date(right.updated_at) - new Date(left.updated_at));
426+
}
427+
406428
async function closeDuplicateInboxIssues(issues, canonicalIssue) {
407429
const closedDuplicateNumbers = [];
408430

0 commit comments

Comments
 (0)