Skip to content

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

Merged
fregante merged 10 commits into
mainfrom
clear-pr-merge-commit-message
Feb 11, 2023
Merged

fregante merged 10 commits into
mainfrom
clear-pr-merge-commit-message

Conversation

@fregante

@fregante fregante commented Feb 10, 2023 •

Copy link
Copy Markdown
Member

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
Copy Markdown
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


// 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
Copy Markdown
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
Copy Markdown
Member

Choose a reason for hiding this comment

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

@fregante fregante Feb 10, 2023 •

Copy link
Copy Markdown
Member Author

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
Copy Markdown
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
Copy Markdown
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.

2 participants