From ca94c2de7d0c207bfeab0d0375809b1b1e279343 Mon Sep 17 00:00:00 2001 From: yiyixuxu Date: Wed, 21 Oct 2026 09:30:33 +0200 Subject: [PATCH] Do not count issues the PR author opened after the PR as linked Applies to both the fixes-issue label and the issue-link reminder. Co-Authored-By: Claude Fable 5.1 --- .github/workflows/pr_labeler.yml | 12 +++++++++--- utils/remind_link_issue.py | 21 ++++++++++++++++----- 2 files changed, 25 insertions(+), 8 deletions(-) diff --git a/.github/workflows/pr_labeler.yml b/.github/workflows/pr_labeler.yml index 691dc2b6f0..8147ef7794 100644 --- a/.github/workflows/pr_labeler.yml +++ b/.github/workflows/pr_labeler.yml @@ -52,6 +52,7 @@ jobs: # fixes-issue - name: Check for linked closing issues + # An issue the PR author opened after the PR does not count as linked. if: ${{ !cancelled() }} run: | OWNER="${REPO%/*}" @@ -62,13 +63,18 @@ jobs: query($owner: String!, $name: String!, $number: Int!) { repository(owner: $owner, name: $name) { pullRequest(number: $number) { - closingIssuesReferences(first: 1) { - totalCount + createdAt + author { login } + closingIssuesReferences(first: 50) { + nodes { createdAt author { login } } } } } }' \ - --jq '.data.repository.pullRequest.closingIssuesReferences.totalCount') + --jq '.data.repository.pullRequest as $pr + | [$pr.closingIssuesReferences.nodes[] + | select(.author.login != $pr.author.login or .createdAt < $pr.createdAt)] + | length') HAS_LABEL=$(gh api "repos/${REPO}/issues/${PR_NUMBER}/labels" --jq 'any(.[]; .name == "fixes-issue")') if [ "${COUNT:-0}" -gt 0 ]; then if [ "$HAS_LABEL" != "true" ]; then diff --git a/utils/remind_link_issue.py b/utils/remind_link_issue.py index ddfc736a3e..4328820e0b 100644 --- a/utils/remind_link_issue.py +++ b/utils/remind_link_issue.py @@ -16,8 +16,9 @@ Script to remind PR authors to link an issue, and to escalate unresolved reminde Behavior: - Scans open, non-draft PRs. -- A PR is considered "linked" if GitHub's GraphQL `closingIssuesReferences` returns > 0 - (covers both `Fixes #N` keywords in the body and issues linked via the GitHub UI). +- A PR is considered "linked" if GitHub's GraphQL `closingIssuesReferences` returns an + issue (covers both `Fixes #N` keywords in the body and issues linked via the GitHub UI), + not counting issues the PR author opened after the PR. - If a PR is not linked and has no reminder yet, the script posts a single friendly reminder comment warning that the PR may be auto-closed. - If a PR only has an old-style reminder (posted before the auto-close notice existed), @@ -86,8 +87,13 @@ GRAPHQL_QUERY = """ query($owner: String!, $name: String!, $number: Int!) { repository(owner: $owner, name: $name) { pullRequest(number: $number) { - closingIssuesReferences(first: 1) { - totalCount + createdAt + author { login } + closingIssuesReferences(first: 50) { + nodes { + createdAt + author { login } + } } } } @@ -107,7 +113,12 @@ def has_linked_issue(token, owner, name, number): data = payload.get("data") if not data: return False - return data["repository"]["pullRequest"]["closingIssuesReferences"]["totalCount"] > 0 + pr = data["repository"]["pullRequest"] + pr_author = (pr["author"] or {}).get("login") + return any( + (issue["author"] or {}).get("login") != pr_author or issue["createdAt"] < pr["createdAt"] + for issue in pr["closingIssuesReferences"]["nodes"] + ) def author_checkbox_checked(pr):