From 667087eb3932a1a7b373e55e9860526cd9fcf374 Mon Sep 17 00:00:00 2001 From: carlos-alm Date: Sat, 8 Aug 2026 03:39:21 -0600 Subject: [PATCH 1/2] fix(ci): add non-blocking reminder for non-closing issue references in PRs MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Closes #2181 Three issues (#1763, #1867, #1888) were already fully fixed and merged to main but stayed open because the merging PR used "Refs #N" instead of a closing keyword — which looks like a valid reference but does not trigger GitHub's auto-close on merge. Nothing previously caught this. A hard-failing CI gate isn't the right shape here: a non-closing reference ("Refs #N", "Related #N", partial fixes) is often intentional, and text alone can't distinguish that from a mistake. Added a new closing-keyword-check.yml workflow that scans the PR body for issue references using a non-closing phrase with no closing keyword for the same number, and posts (or clears) a single informational PR comment — it never fails the build, it just makes the gap visible for a human to confirm. Uses pull_request_target since the check only reads the trusted event payload's body field (no checkout, no code execution), so it also works on fork PRs, unlike plain pull_request which gets a read-only token there. Also clarified the existing "Related issues" hint in .github/PULL_REQUEST_TEMPLATE.md to spell out that Refs/Related won't auto-close, addressing the PR-template-reminder option directly. --- .github/PULL_REQUEST_TEMPLATE.md | 4 +- .github/workflows/closing-keyword-check.yml | 90 +++++++++++++++++++++ 2 files changed, 93 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/closing-keyword-check.yml diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md index 0afcbfbfd..cfce27287 100644 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ b/.github/PULL_REQUEST_TEMPLATE.md @@ -26,4 +26,6 @@ N/A ## Related issues - + diff --git a/.github/workflows/closing-keyword-check.yml b/.github/workflows/closing-keyword-check.yml new file mode 100644 index 000000000..686a39cf0 --- /dev/null +++ b/.github/workflows/closing-keyword-check.yml @@ -0,0 +1,90 @@ +# Reminds PR authors when a description references an issue with a non-closing +# phrase ("Refs #N", "Related #N", bare "(#N)") but no closing keyword for that +# same number — the pattern behind issue #2181, where merged PRs silently left +# already-fixed issues open because "Refs #N" looks like a valid reference but +# does not trigger GitHub's auto-close. Informational only: a non-closing +# reference is often intentional (partial fix, related work), so this never +# fails the build — it only makes the gap visible for a human to confirm. +# +# Uses pull_request_target (not pull_request) so the check also works on PRs +# from forks, which get a read-only GITHUB_TOKEN under pull_request. This is +# safe without the workflow_run split codegraph-impact-comment.yml uses, +# because this job never checks out or executes the PR's head content — it +# only reads the trusted event payload's `pull_request.body` field. +name: Closing Keyword Check +on: + pull_request_target: + types: [opened, edited, reopened] + branches: [main] + +permissions: + pull-requests: write + +concurrency: + group: closing-keyword-check-${{ github.event.pull_request.number }} + cancel-in-progress: true + +jobs: + check: + runs-on: ubuntu-latest + steps: + - name: Check for non-closing issue references + uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9 + with: + script: | + const body = context.payload.pull_request.body || ''; + + const closingKeywords = /\b(?:close|closes|closed|fix|fixes|fixed|resolve|resolves|resolved)\s+#(\d+)/gi; + const closedIssues = new Set(); + for (let m; (m = closingKeywords.exec(body)); ) closedIssues.add(m[1]); + + const refPattern = /\b(?:refs?|related(?:\s+to)?|see)\s+#(\d+)|\(#(\d+)\)/gi; + const flagged = new Set(); + for (let m; (m = refPattern.exec(body)); ) { + const num = m[1] || m[2]; + if (!closedIssues.has(num)) flagged.add(num); + } + + const marker = ''; + const prNumber = context.payload.pull_request.number; + const comments = await github.paginate(github.rest.issues.listComments, { + owner: context.repo.owner, + repo: context.repo.repo, + issue_number: prNumber, + }); + const existing = comments.find((c) => c.body.includes(marker)); + + if (flagged.size === 0) { + if (existing) { + await github.rest.issues.deleteComment({ + owner: context.repo.owner, + repo: context.repo.repo, + comment_id: existing.id, + }); + } + return; + } + + const issueList = [...flagged].map((n) => `#${n}`).join(', '); + const commentBody = + `${marker}\n` + + `**Heads up:** this PR references ${issueList} without a closing keyword ` + + '(`Closes #N` / `Fixes #N`). If this PR fully resolves ' + + `${issueList}, update the description so the issue auto-closes on merge — ` + + 'otherwise disregard this comment.'; + + if (existing) { + await github.rest.issues.updateComment({ + owner: context.repo.owner, + repo: context.repo.repo, + comment_id: existing.id, + body: commentBody, + }); + } else { + await github.rest.issues.createComment({ + owner: context.repo.owner, + repo: context.repo.repo, + issue_number: prNumber, + body: commentBody, + }); + } From f518b4b7da4d367de82e4aba40420ccb8dcb36c9 Mon Sep 17 00:00:00 2001 From: carlos-alm Date: Sat, 8 Aug 2026 04:04:34 -0600 Subject: [PATCH 2/2] fix(ci): restrict closing-keyword-check comment lookup to bot-authored comments Greptile flagged (PR #2351) that matching an existing comment purely by marker text lets a PR participant plant the marker in their own comment and have a later edit/reopen event overwrite or delete it. Restrict the lookup to comments authored by github-actions[bot]. Filed #2352 for the identical pre-existing pattern in codegraph-impact-comment.yml, out of scope for this PR. --- .github/workflows/closing-keyword-check.yml | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/.github/workflows/closing-keyword-check.yml b/.github/workflows/closing-keyword-check.yml index 686a39cf0..98264a2eb 100644 --- a/.github/workflows/closing-keyword-check.yml +++ b/.github/workflows/closing-keyword-check.yml @@ -52,7 +52,12 @@ jobs: repo: context.repo.repo, issue_number: prNumber, }); - const existing = comments.find((c) => c.body.includes(marker)); + // Restrict to the workflow's own bot-authored comments — matching on the + // marker text alone would let a PR participant plant it in their own + // comment and have a later edit/reopen event overwrite or delete it. + const existing = comments.find( + (c) => c.body.includes(marker) && c.user.login === 'github-actions[bot]' + ); if (flagged.size === 0) { if (existing) {