Skip to content

Improve Github keyword matching #674

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

Merged

Conversation

gstokkink
Copy link
Contributor

Github allows additional spacing and a single colon character between the Github keyword and the issue number.

Copy link

No linked issues found. Please add the corresponding issues in the pull request description.
Use GitHub automation to close the issue when a PR is merged

@gstokkink
Copy link
Contributor Author

gstokkink commented May 21, 2025

@simoneb @agubler Github allows a slightly different (more lenient) syntax for closing issues than your Github Action currently allows. This bring it more in sync.

So, it will also allow, for instance, Resolves: #1234 or Fixes #1234.

@simoneb simoneb requested a review from Copilot May 21, 2025 13:50
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR updates issue-reference extraction to support an optional colon and flexible spacing after GitHub keywords.

  • Broaden extractLocalIssues and extractExternalIssues regex patterns to allow a colon and extra whitespace before the issue number or URL
  • Adjust mock data in tests to include cases with colons and varied spaces

Reviewed Changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.

File Description
src/util.js Updated both extractLocalIssues and extractExternalIssues regexes
mocks/@actions/github.js Modified mock PR bodies to include colon variants and extra whitespace
Comments suppressed due to low confidence (2)

src/util.js:137

  • Same issue in the external-issues regex: (?:\s*:)? won’t match a colon directly after the keyword. Switch to (?::)? to cover both closes: and closes : cases.
/\b(close|closes|closed|fix|fixes|fixed|resolve|resolves|resolved)(?:\s*:)?\s+(https?:\/\/github\.com\/)*.../gim;

src/util.js:121

  • Add unit tests covering cases with no-space colon (e.g., fixes:#123), colon with space (e.g., fixes: #123), and without a colon (e.g., fixes #123) to confirm the updated regex handles all variants.
function extractLocalIssues(body) {

Copy link
Member

@simoneb simoneb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you please create new test cases instead of modifying existing ones?

Github allows additional spacing and a single colon character between the Github keyword and the issue number.
@gstokkink gstokkink force-pushed the improve-github-keyword-matching branch from 4fe395a to 73751dc Compare May 21, 2025 14:02
@gstokkink
Copy link
Contributor Author

@simoneb not sure why, that would involve a lot more effort. The current tests are fine, just the mocked data is slightly adjusted to also test the more lenient syntax, along with the existing syntax.

@simoneb
Copy link
Member

simoneb commented May 21, 2025

@gstokkink I'm testing your modified regexp for local issues but I can't seem to make it match what you suggest should be matching, e.g. the double spaces. Is this scenario intended to be handled?

image

@gstokkink
Copy link
Contributor Author

@simoneb interesting, that should match as well. I'd expect the \s+ to take care of that. Might be a case of greedy matching going wrong, in which case I need to change the regex slightly. I'll check tomorrow.

@simoneb
Copy link
Member

simoneb commented May 22, 2025

@gstokkink having specific tests for the new format may help, because I'm confused as well. Reading the new regexp you wrote, it makes sense to me, but then the test I did doesn't work, so I hope that tests will clarify this. We should consider testing the regexp matching functions in isolation.

@gstokkink
Copy link
Contributor Author

gstokkink commented May 22, 2025

@simoneb ah, I see your mistake. You added the g flag, which makes the regex stateful. This is useful when using exec to progressively find matches in a string (as in the code), but won't work for your tests in the console. Try dropping the g flag (i.e., use im instead of gim) and it should work as expected.

@simoneb simoneb merged commit 35f3af9 into nearform-actions:main May 22, 2025
2 of 3 checks passed
@gstokkink
Copy link
Contributor Author

gstokkink commented May 22, 2025

@simoneb Thanks for merging! Can we get a new release as well? 😄

Edit: cheers!

@gstokkink gstokkink deleted the improve-github-keyword-matching branch May 22, 2025 11:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants