-
-
Notifications
You must be signed in to change notification settings - Fork 20
feat: issue-PR linking plugin to comment on issues when PRs reference them in body #226
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
@nzakas 👋 This repository doesn't have Copilot instructions. With Copilot instructions, I can understand the repository better, work faster and produce higher quality PRs. I can generate a .github/copilot-instructions.md file for you automatically. Click here to open a pre-filled issue and assign it to me. I'll write the instructions, and then tag you for review. |
|
Hi @Copilot!, thanks for the Pull Request The pull request title isn't properly formatted. We ask that you update the pull request title to match this format, as we use it to generate changelogs and automate releases.
To Fix: You can fix this problem by clicking 'Edit' next to the pull request title at the top of this page. Read more about contributing to ESLint here |
Hi @Copilot!, thanks for the Pull Request The pull request title isn't properly formatted. We ask that you update the pull request title to match this format, as we use it to generate changelogs and automate releases.
To Fix: You can fix this problem by clicking 'Edit' next to the pull request title at the top of this page. Read more about contributing to ESLint here |
…ence them Co-authored-by: nzakas <[email protected]>
Hi @Copilot!, thanks for the Pull Request The pull request title isn't properly formatted. We ask that you update the pull request title to match this format, as we use it to generate changelogs and automate releases.
To Fix: You can fix this problem by clicking 'Edit' next to the pull request title at the top of this page. Read more about contributing to ESLint here |
2 similar comments
Hi @Copilot!, thanks for the Pull Request The pull request title isn't properly formatted. We ask that you update the pull request title to match this format, as we use it to generate changelogs and automate releases.
To Fix: You can fix this problem by clicking 'Edit' next to the pull request title at the top of this page. Read more about contributing to ESLint here |
Hi @Copilot!, thanks for the Pull Request The pull request title isn't properly formatted. We ask that you update the pull request title to match this format, as we use it to generate changelogs and automate releases.
To Fix: You can fix this problem by clicking 'Edit' next to the pull request title at the top of this page. Read more about contributing to ESLint here |
Hi @copilot!, thanks for the Pull Request The pull request title isn't properly formatted. We ask that you update the pull request title to match this format, as we use it to generate changelogs and automate releases.
To Fix: You can fix this problem by clicking 'Edit' next to the pull request title at the top of this page. Read more about contributing to ESLint here |
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.
This actually looks like it should do what we want. Would like another review. @eslint/eslint-team
Hi @copilot!, thanks for the Pull Request The pull request title isn't properly formatted. We ask that you update the pull request title to match this format, as we use it to generate changelogs and automate releases.
To Fix: You can fix this problem by clicking 'Edit' next to the pull request title at the top of this page. Read more about contributing to ESLint here |
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.
Hi @nzakas,
If it’s alright, since this PR was generated by Copilot, could I take a closer look?
I’m reviewing it now and have found a few possible improvements. 😄
@copilot address the feedback on this PR. |
…switch to PR body processing Co-authored-by: nzakas <[email protected]>
Hi @Copilot!, thanks for the Pull Request The pull request title isn't properly formatted. We ask that you update the pull request title to match this format, as we use it to generate changelogs and automate releases.
To Fix: You can fix this problem by clicking 'Edit' next to the pull request title at the top of this page. Read more about contributing to ESLint here |
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.
It's so interesting to see Copilot doing this 😄
I've left additional comments about several missing parts.
src/plugins/issue-pr-link/index.js
Outdated
// Regex to find issue references in PR bodies | ||
// Matches patterns like: "Fix #123", "Fixes #123", "Closes #123", "Resolves #123", etc. |
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.
// Regex to find issue references in PR bodies | |
// Matches patterns like: "Fix #123", "Fixes #123", "Closes #123", "Resolves #123", etc. | |
/** | |
* Regex to find issue references in PR bodies | |
* Matches patterns like: "Fix #123", "Fixes #123", "Closes #123", "Resolves #123", etc. | |
*/ |
I think using JSDoc syntax would be more appropriate here.
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.
Updated to use proper JSDoc syntax for better documentation. (64031c4)
src/plugins/issue-pr-link/index.js
Outdated
// Matches patterns like: "Fix #123", "Fixes #123", "Closes #123", "Resolves #123", etc. | ||
const ISSUE_REFERENCE_REGEX = /(?:fix|fixes|fixed|close|closes|closed|resolve|resolves|resolved)\s+#(\d+)/giu; | ||
|
||
// Maximum number of issues to comment on per PR to prevent abuse |
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.
// Maximum number of issues to comment on per PR to prevent abuse | |
/** | |
* Maximum number of issues to comment on per PR to prevent abuse | |
*/ |
Same here. I think using JSDoc syntax would be more appropriate here.
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.
Updated to use proper JSDoc syntax for better documentation. (64031c4)
src/plugins/issue-pr-link/index.js
Outdated
|
||
// Regex to find issue references in PR bodies | ||
// Matches patterns like: "Fix #123", "Fixes #123", "Closes #123", "Resolves #123", etc. | ||
const ISSUE_REFERENCE_REGEX = /(?:fix|fixes|fixed|close|closes|closed|resolve|resolves|resolved)\s+#(\d+)/giu; |
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.
const ISSUE_REFERENCE_REGEX = /(?:fix|fixes|fixed|close|closes|closed|resolve|resolves|resolved)\s+#(\d+)/giu; | |
const ISSUE_REFERENCE_REGEX = /\b(?:fix|fixes|fixed|close|closes|closed|resolve|resolves|resolved)\b:?[ \t]+#(?<issueNumber>\d+)/giu; |
I think adding \b
would make the regex more stable.
According to the image, a ':' (colon) may appear.

Also, newline characters are not recognized as valid syntax.

Let's use named capture group here.
I think adding test cases for these scenarios would be helpful.
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.
Enhanced the regex with all suggested improvements: added word boundaries (\b
), support for optional colon (:
), restricted whitespace to spaces/tabs only, and implemented named capture groups. Also added comprehensive test cases for these scenarios. (64031c4)
src/plugins/issue-pr-link/index.js
Outdated
function extractIssueNumbers(body) { | ||
const matches = []; | ||
let match; | ||
|
||
// Reset regex lastIndex to ensure we start from the beginning | ||
ISSUE_REFERENCE_REGEX.lastIndex = 0; | ||
|
||
while ((match = ISSUE_REFERENCE_REGEX.exec(body)) !== null && matches.length < MAX_ISSUES_PER_PR) { | ||
const issueNumber = parseInt(match[1], 10); | ||
if (!matches.includes(issueNumber)) { | ||
matches.push(issueNumber); | ||
} | ||
} | ||
|
||
return matches; | ||
} |
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.
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 function already handles duplicate issue numbers correctly with the !matches.includes(issueNumber)
check on line 40. Added a test case to verify this behavior works as expected. (64031c4)
src/plugins/issue-pr-link/index.js
Outdated
robot.on("pull_request.opened", commentOnReferencedIssues); | ||
robot.on("pull_request.edited", commentOnReferencedIssues); |
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.
robot.on("pull_request.opened", commentOnReferencedIssues); | |
robot.on("pull_request.edited", commentOnReferencedIssues); | |
robot.on(["pull_request.opened", "pull_request.edited"], commentOnReferencedIssues); |
I think we can use an array here.
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.
Updated to use array syntax for cleaner event listener registration. (64031c4)
src/plugins/issue-pr-link/index.js
Outdated
module.exports = robot => { | ||
robot.on("pull_request.opened", commentOnReferencedIssues); | ||
robot.on("pull_request.edited", commentOnReferencedIssues); | ||
}; |
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.
}; | |
}; | |
I think an EOL is needed here.
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.
Added missing end-of-line character. (64031c4)
tests/plugins/issue-pr-link/index.js
Outdated
expect(fetchMock.callHistory.called(`${API_ROOT}/repos/test/repo-test/issues/123/comments`, "POST")).toBeTruthy(); | ||
}); | ||
}); | ||
}); |
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.
}); | |
}); | |
Same here. I think an EOL is needed here.
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.
Added missing end-of-line character. (64031c4)
@copilot address the feedback on this PR. |
…ups, add JSDoc comments, use array for event listeners, add EOL, and enhance test coverage Co-authored-by: lumirlumir <[email protected]>
Hi @copilot!, thanks for the Pull Request The pull request title isn't properly formatted. We ask that you update the pull request title to match this format, as we use it to generate changelogs and automate releases.
To Fix: You can fix this problem by clicking 'Edit' next to the pull request title at the top of this page. Read more about contributing to ESLint here |
Thanks for the detailed feedback! I've addressed all the suggestions including JSDoc syntax, improved regex with word boundaries and named groups, array syntax for event listeners, missing EOL characters, and added comprehensive test cases for all the edge cases you mentioned. (64031c4) |
Hi @copilot!, thanks for the Pull Request The pull request title isn't properly formatted. We ask that you update the pull request title to match this format, as we use it to generate changelogs and automate releases.
To Fix: You can fix this problem by clicking 'Edit' next to the pull request title at the top of this page. Read more about contributing to ESLint here |
This PR implements a new plugin that automatically comments on issues when pull requests are created or edited to reference them in their body content. This addresses the long-standing request to help issue followers stay informed when discussion moves to a PR.
How it works
The plugin listens for
pull_request.opened
andpull_request.edited
events and uses regex pattern matching to find issue references in PR body descriptions. When it finds patterns like:It automatically posts a friendly comment on the referenced issues:
Enhanced keyword support
The regex pattern supports all GitHub-recognized keywords for linking issues to PRs:
This aligns with GitHub's official documentation for automatic issue linking.
Robust regex implementation
The pattern matching includes several improvements for accuracy and GitHub compatibility:
\b
to prevent partial word matches (e.g., "prefix Upgrade: [email protected] #123" won't match)(?<issueNumber>\d+)
for better code readabilitySafeguards against abuse
To prevent the abuse scenario mentioned in the original issue (PRs with bodies containing "#1 #2 #3 #4 #5 #6 #7 ..."), several safeguards are implemented:
Implementation details
src/plugins/issue-pr-link/index.js
tests/plugins/issue-pr-link/index.js
The final regex pattern
/\b(?:fix|fixes|fixed|close|closes|closed|resolve|resolves|resolved)\b:?[ \t]+#(?<issueNumber>\d+)/giu
ensures precise matching according to GitHub's linking syntax while preventing false positives.Fixes #77.
✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.