Skip to content
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

Fix "closing keyword" logic in clear-pr-merge-commit-message #6328

Merged
merged 10 commits into from Feb 11, 2023

Conversation

fregante
Copy link
Member

@fregante fregante commented Feb 10, 2023

Test URLs

Tested in #6315

Should also be testable in refined-github/sandbox#53

Demo

Screen.Recording.5.mov

const issueLink = keyword.nextElementSibling as HTMLAnchorElement; // Account for issues not in the same repo
const sibling = keyword.nextElementSibling!;
// Get the full URL so it works on issues not in the same repo
const issueLink = sibling instanceof HTMLAnchorElement ? sibling : select('a', sibling)!;
Copy link
Member Author

Choose a reason for hiding this comment

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

sibling became a span

Before

Screenshot 2

After

Screenshot 4

@@ -19,10 +19,12 @@ async function init(): Promise<void | false> {
}

// Preserve closing issues numbers when a PR is merged into a non-default branch since GitHub doesn't close them #4531
if (getBranches().base !== await getDefaultBranch()) {
if (getBranches().base.branch !== await getDefaultBranch()) {
Copy link
Member Author

Choose a reason for hiding this comment

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

On cross-repo PRs, this comparison was between "user:branch" and "branch", so it would never match.

This caused #6122 to appear on every cross-repo PR instead of just non-default-branch PRs

Copy link
Member

Choose a reason for hiding this comment

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

Copy link
Member Author

@fregante fregante Feb 10, 2023

Choose a reason for hiding this comment

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

What about it? The review that prompted this change was #6122 (comment), which was correct. It's 4a1a31d (#6122) that introduced the bug

Copy link
Member

Choose a reason for hiding this comment

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

Oh I though you meant something else with your comment.
Never mind

@fregante fregante added the bug label Feb 10, 2023
@fregante fregante marked this pull request as ready for review February 10, 2023 13:41
Comment on lines 31 to 34
// https://docs.github.com/en/get-started/writing-on-github/working-with-advanced-formatting/using-keywords-in-issues-and-pull-requests#linking-a-pull-request-to-an-issue
for (const [line] of originalMessage.matchAll(/(fix(es|ed)?|close[sd]?|resolve[sd]?)([^\n]+)/gi)) {
// Ensure it includes a reference or URL
if (/#\d+/.test(line) || line.includes('http')) {
Copy link
Member Author

Choose a reason for hiding this comment

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

This restores my original suggestion, but looser #4531 (comment)

All of this code exists to "clear the field, except some data". The DOM-based approach:

  • adds data from other parts, which was not part of GitHub’s suggested message
  • breaks more easily (as seen)

This regex will not cleanly keep just the keywords, but that's fine, because that content was already in the field.

@fregante fregante enabled auto-merge (squash) February 11, 2023 09:16
@fregante fregante merged commit 05915e2 into main Feb 11, 2023
@fregante fregante deleted the clear-pr-merge-commit-message branch February 11, 2023 09:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

Successfully merging this pull request may close these issues.

None yet

2 participants