generator icon indicating copy to clipboard operation
generator copied to clipboard

[BUG] close-prs-for-unapproved-issues falsely closes valid prs

Open devxdh opened this issue 1 week ago • 0 comments

Describe the bug.

In .github/workflows/close-prs-for-unapproved-issues.yml, two parsing behaviors can lead to valid contributor PRs being automatically closed:

  1. 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 #123 and #43. When checking issue #123 (an old issue from 2019 without the Approved Issue label), line 103 immediately posts a comment and closes the PR, even if the author specified a valid approved issue in the body.

  2. Strict issue-linking regex: The current regex expects strictly a single space followed by #:

    /(?:close[sd]?|fix(?:e[sd])?|resolve[sd]?)\s#(\d+)/gi
    

    It 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 #123 When any of these formats are used, matches.length is 0, causing the workflow (line 80) to report that no linked issue was found and close the PR.

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

  1. 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.
    
  2. 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

  1. Strip HTML comments from the PR body before running the regex:
    const cleanBody = prBody.replace(/<!--[\s\S]*?-->/g, '');
    
  2. 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?

Are you willing to work on this issue ?

Yes I am willing to submit a PR!

devxdh avatar Nov 25 '26 12:11 devxdh