[BUG] close-prs-for-unapproved-issues falsely closes valid prs
Describe the bug.
In .github/workflows/close-prs-for-unapproved-issues.yml, two parsing behaviors can lead to valid contributor PRs being automatically closed:
-
Unstripped template comments: The default pull request template (
.github/pull-request-template.md, lines 14–15) includes the following instructions inside an HTML comment:<!-- If you refer to a particular issue, provide its number, othewise, remove this section. For example, `Resolves #123` or `Fixes #43` -->Because HTML comments are not stripped before matching (line 74), the workflow extracts issues
#123and#43. When checking issue#123(an old issue from 2019 without theApproved Issuelabel), line 103 immediately posts a comment and closes the PR, even if the author specified a valid approved issue in the body. -
Strict issue-linking regex: The current regex expects strictly a single space followed by
#:/(?:close[sd]?|fix(?:e[sd])?|resolve[sd]?)\s#(\d+)/giIt does not match standard GitHub issue reference formats such as:
- Colons:
Fixes: #123,Resolves: #123 - Full GitHub URLs:
Fixes https://github.com/asyncapi/generator/issues/123 - Multiple spaces:
Fixes #123When any of these formats are used,matches.lengthis0, causing the workflow (line 80) to report that no linked issue was found and close the PR.
- Colons:
Expected behavior
- HTML comments should be stripped from the PR description before extracting issue numbers so that template guidance comments do not trigger false checks.
- Common issue linking formats (optional colons, multiple spaces, full issue URLs) should be recognized by the regex pattern.
Screenshots
_No response
How to Reproduce
- Test regex against standard issue link formats in Node:
node -e " const pattern = /(?:close[sd]?|fix(?:e[sd])?|resolve[sd]?)\s#(\d+)/gi; console.log('Fixes: #123 -> matches:', [...'Fixes: #123'.matchAll(pattern)].length); console.log('Fixes URL -> matches:', [...'Fixes https://github.com/asyncapi/generator/issues/123'.matchAll(pattern)].length); " # Both print 0 matches, triggering automated PR closure. - Test HTML comment parsing:
node -e " const templateComment = '<!-- For example, Resolves #123 or Fixes #43 -->'; const pattern = /(?:close[sd]?|fix(?:e[sd])?|resolve[sd]?)\s#(\d+)/gi; console.log([...templateComment.matchAll(pattern)].map(m => m[1])); # Output: ['123', '43'] "
Proposed Fix
- Strip HTML comments from the PR body before running the regex:
const cleanBody = prBody.replace(/<!--[\s\S]*?-->/g, ''); - Update the regex to support optional colons, arbitrary whitespace, and full URLs:
const issuePattern = /(?:close[sd]?|fix(?:e[sd])?|resolve[sd]?):?\s*(?:#|https:\/\/github\.com\/[^\/\s]+\/[^\/\s]+\/issues\/)(\d+)/gi;
Open to maintainer feedback on whether any additional reference formats or exclusions should be accommodated.
🖥️ Device Information [optional]
- Operating System (OS): Fedora Linux Workstation 44
- Browser: Chrome
- Browser Version: 154
👀 Have you checked for similar open issues?
- [x] I checked and didn't find similar issue
🏢 Have you read the Contributing Guidelines?
- [x] I have read the Contributing Guidelines
Are you willing to work on this issue ?
Yes I am willing to submit a PR!