Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 30 additions & 10 deletions .github/scripts/handle-codex-pr-comments.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -144,9 +144,11 @@ async function getPullRequestFromInbox(prNumber) {
}

async function listInboxPullRequestNumbers() {
const existingIssue = chooseCanonicalInboxIssue(await findInboxIssues());
const inboxIssues = await findInboxIssues();

return existingIssue ? extractInboxPullRequestNumbers(existingIssue.body ?? "") : [];
return [
...new Set(inboxIssues.flatMap((issue) => extractInboxPullRequestNumbers(issue.body ?? ""))),
];
}

function extractInboxPullRequestNumbers(body) {
Expand Down Expand Up @@ -392,21 +394,39 @@ async function findInboxIssues() {
}

function isManagedInboxIssue(issue) {
return (
issue.title === inboxIssueTitle &&
issue.body?.includes(inboxMarker) &&
issue.labels?.some((label) => label.name === inboxIssueLabel)
);
return isLabeledInboxIssue(issue) || isMigratableInboxIssue(issue);
}

function isLabeledInboxIssue(issue) {
return hasInboxIdentity(issue) && issue.labels?.some((label) => label.name === inboxIssueLabel);
}

function isMigratableInboxIssue(issue) {
return hasInboxIdentity(issue) && isTrustedInboxIssueCreator(issue);
}

function hasInboxIdentity(issue) {
return issue.title === inboxIssueTitle && issue.body?.includes(inboxMarker);
Comment thread
max23468 marked this conversation as resolved.
}

function isTrustedInboxIssueCreator(issue) {
return ["app/github-actions", "github-actions[bot]"].includes(issue.user?.login);
}

function chooseCanonicalInboxIssue(issues) {
const openIssues = issues.filter((issue) => issue.state === "open");

return (
issues
.filter((issue) => issue.state === "open")
.sort((left, right) => new Date(right.updated_at) - new Date(left.updated_at))[0] ?? null
sortIssuesByUpdatedDesc(openIssues.filter(isLabeledInboxIssue))[0] ??
sortIssuesByUpdatedDesc(openIssues.filter(isMigratableInboxIssue))[0] ??
null
);
}

function sortIssuesByUpdatedDesc(issues) {
return [...issues].sort((left, right) => new Date(right.updated_at) - new Date(left.updated_at));
}

async function closeDuplicateInboxIssues(issues, canonicalIssue) {
const closedDuplicateNumbers = [];

Expand Down
Loading