-
-
Notifications
You must be signed in to change notification settings - Fork 369
fix: Prevent duplicate issue creation in PR automation workflow #6517
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
The workflow was creating duplicate issues when multiple trigger events (opened, edited, synchronize, etc.) fired in quick succession. Both workflow runs would check the PR simultaneously, find no issue reference, and each create a new issue. Added a check to search for existing issues created by this automation before creating a new one. The workflow now searches for open issues that contain the PR URL and were created by github-actions bot, preventing duplicate issue creation. Fixes the issue where PR #6386 had two issues created (#6499 and #6500).
Bug: Search Filter Fails to Detect IssuesThe search query's |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nice, thanks!
|
@sentry review |
Bug: Search Fails to Filter by Bot CreatorThe search query for existing issues doesn't filter by the |
| const existingIssuesResponse = await github.rest.search.issuesAndPullRequests({ | ||
| q: `repo:${context.repo.owner}/${context.repo.repo} is:issue is:open "${prUrl}" in:title in:body`, | ||
| }); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Bug: The GitHub issue search query is missing an <code>author</code> filter, causing it to incorrectly match issues created by any user, not just the automation bot.
Severity: HIGH | Confidence: 1.00
🔍 Detailed Analysis
The GitHub API search query in `existingIssuesResponse` is intended to find duplicate issues created by the automation. However, it is missing an `author` filter to limit the search to issues created by the `github-actions` bot. Consequently, the search will match any open issue that contains the pull request URL, regardless of who created it. If a user manually creates an issue and references the PR URL, the automation will incorrectly determine an issue already exists and will skip creating its own necessary tracking issue.
💡 Suggested Fix
Update the search query q to include an author filter to only find issues created by the bot. For example: q: epo:${context.repo.owner}/${context.repo.repo} is:issue is:open "${prUrl}" in:title in:body author:github-actions.
🤖 Prompt for AI Agent
Fix this bug. In .github/workflows/create-issue-for-unreferenced-pr.yml at lines 73-75:
The GitHub API search query in `existingIssuesResponse` is intended to find duplicate
issues created by the automation. However, it is missing an `author` filter to limit the
search to issues created by the `github-actions` bot. Consequently, the search will
match any open issue that contains the pull request URL, regardless of who created it.
If a user manually creates an issue and references the PR URL, the automation will
incorrectly determine an issue already exists and will skip creating its own necessary
tracking issue.
Did we get this right? 👍 / 👎 to inform future reviews.
| // Check if there's already an issue created by this automation for this PR | ||
| // Search for issues that mention this PR and were created by github-actions bot | ||
| const existingIssuesResponse = await github.rest.search.issuesAndPullRequests({ | ||
| q: `repo:${context.repo.owner}/${context.repo.repo} is:issue is:open "${prUrl}" in:title in:body`, | ||
| }); | ||
| if (existingIssuesResponse.data.total_count > 0) { | ||
| const existingIssue = existingIssuesResponse.data.items[0]; | ||
| console.log(`An issue (#${existingIssue.number}) already exists for PR #${prNumber}, skipping creation.`); | ||
| return; | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The comment mentions filtering for issues 'created by github-actions bot', but the search query doesn't actually include a creator filter. This could result in false positives by matching issues created by other users or bots that happen to mention the PR URL. Consider updating the search query to filter by creator: creator:github-actions or user:github-actions to ensure you're only detecting issues created by this automation.
Severity: MEDIUM
🤖 Prompt for AI Agent
Fix this code. In .github/workflows/create-issue-for-unreferenced-pr.yml#L71-L81: The
comment mentions filtering for issues 'created by github-actions bot', but the search
query doesn't actually include a creator filter. This could result in false positives by
matching issues created by other users or bots that happen to mention the PR URL.
Consider updating the search query to filter by creator: `creator:github-actions` or
`user:github-actions` to ensure you're only detecting issues created by this automation.
Did we get this right? 👍 / 👎 to inform future reviews.
The workflow was creating duplicate issues when multiple trigger events (opened, edited, synchronize, etc.) fired in quick succession. Both workflow runs would check the PR simultaneously, find no issue reference, and each create a new issue.
Added a check to search for existing issues created by this automation before creating a new one. The workflow now searches for open issues that contain the PR URL and were created by github-actions bot, preventing duplicate issue creation.
Fixes the issue where PR #6386 had two issues created (#6499 and #6500).
#skip-changelog