-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Changes from 3 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
f012bb6
Fix "closing keyword" logic in `clear-pr-merge-commit-message`
fregante ad6c2ea
Comments
fregante a855ee1
Extract
fregante 9cc5ff3
Lint
fregante 75cfd13
Uppercase closing keyword
fregante 2a94828
Merge remote-tracking branch 'origin/main' into clear-pr-merge-commit…
fregante efd7ea9
Just use the commit message
fregante 1856d14
Drop logging
fregante 02661e5
Extract
fregante 7d7f194
Fix lockfile
fregante File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,7 +4,7 @@ import {set} from 'text-field-edit'; | |
import * as pageDetect from 'github-url-detection'; | ||
|
||
import features from '../feature-manager'; | ||
import {getBranches} from './update-pr-from-base-branch'; | ||
import {getBranches} from '../github-helpers/pr-branches'; | ||
import getDefaultBranch from '../github-helpers/get-default-branch'; | ||
import onPrMergePanelOpen from '../github-events/on-pr-merge-panel-open'; | ||
|
||
|
@@ -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()) { | ||
for (const keyword of select.all('.comment-body .issue-keyword[aria-label^="This pull request closes"]')) { | ||
const closingKeyword = keyword.textContent!.trim(); // Keep the keyword as-is (closes, fixes, etc.) | ||
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)!; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
preservedContent.add(closingKeyword + ' ' + issueLink.href); | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import select from 'select-dom'; | ||
import splitOnFirst from 'split-on-first'; | ||
|
||
export type PrReference = { | ||
/** @example fregante/mem:main */ | ||
full: string; | ||
|
||
/** @example "main" on same-repo PRs, "fregante:main" on cross-repo PRs */ | ||
local: string; | ||
|
||
/** @example fregante */ | ||
owner: string; | ||
|
||
/** @example mem */ | ||
name: string; | ||
|
||
/** @example main */ | ||
branch: string; | ||
}; | ||
|
||
function parseReference(referenceElement: HTMLElement): PrReference { | ||
const {title: full, textContent: local} = referenceElement; | ||
const [nameWithOwner, branch] = splitOnFirst(full, ':') as [string, string]; | ||
const [owner, name] = nameWithOwner.split(':'); | ||
return {full, owner, name, branch, local: local!.trim()}; | ||
} | ||
|
||
// TODO: Use in more places, like anywhere '.base-ref' appears | ||
export function getBranches(): {base: PrReference; head: PrReference} { | ||
return { | ||
base: parseReference(select('.base-ref')!), | ||
head: parseReference(select('.head-ref')!), | ||
}; | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
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
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.
#6122 (comment)_
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.
What about it? The review that prompted this change was #6122 (comment), which was correct. It's
4a1a31d
(#6122) that introduced the bugThere 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.
Oh I though you meant something else with your comment.
Never mind