diff options
author | 2022-02-17 10:04:43 +0100 | |
---|---|---|
committer | 2022-02-17 10:04:43 +0100 | |
commit | ec9b01c1b1a6888023955ccd690da1566d9c7d65 (patch) | |
tree | b335aa543a8a6338e0ba2d6dd360bc7373c77710 /source/features/use-first-commit-message-for-new-prs.tsx | |
parent | 873c3072ff6a4bfced8bdcbc7510cfd914058be5 (diff) | |
download | refined-github-ec9b01c1b1a6888023955ccd690da1566d9c7d65.tar.gz refined-github-ec9b01c1b1a6888023955ccd690da1566d9c7d65.tar.zst refined-github-ec9b01c1b1a6888023955ccd690da1566d9c7d65.zip |
Fix linkified `use-first-commit-message-for-new-prs` (#5402)
Diffstat (limited to 'source/features/use-first-commit-message-for-new-prs.tsx')
-rw-r--r-- | source/features/use-first-commit-message-for-new-prs.tsx | 26 |
1 files changed, 20 insertions, 6 deletions
diff --git a/source/features/use-first-commit-message-for-new-prs.tsx b/source/features/use-first-commit-message-for-new-prs.tsx index 00d5f28c..a2272e4e 100644 --- a/source/features/use-first-commit-message-for-new-prs.tsx +++ b/source/features/use-first-commit-message-for-new-prs.tsx @@ -6,6 +6,24 @@ import * as textFieldEdit from 'text-field-edit'; import features from '.'; import looseParseInt from '../helpers/loose-parse-int'; +// TODO [2022-05-01]: Drop GHE code and merge function back in init +function getFirstCommitMessage(): string[] { + if (pageDetect.isEnterprise()) { + return select('#commits_bucket [data-url$="compare/commit"] a[title]')!.title.split('\n\n'); + } + + const commitSummaryWrapper = select('.js-commits-list-item a.Link--primary')!.parentElement!; + const commitDescription = select('.js-commits-list-item pre')?.textContent ?? ''; + + // Linkified commit summaries are split into several adjacent links #5382 + const commitSummary = select.all(':scope > a', commitSummaryWrapper) + .map(commitTitleLink => commitTitleLink.innerHTML) + .join('') + .replace(/<\/?code>/g, '`'); + + return [commitSummary, commitDescription]; +} + async function init(): Promise<void | false> { const commitCountIcon = await elementReady('div.Box.mb-3 .octicon-git-commit'); const commitCount = commitCountIcon?.nextElementSibling; @@ -13,18 +31,14 @@ async function init(): Promise<void | false> { return false; } - const [prTitle, ...prMessage] = (pageDetect.isEnterprise() - ? select('#commits_bucket [data-url$="compare/commit"] a[title]')!.title // TODO [2022-05-01]: Remove GHE code - : select('#commits_bucket .js-commits-list-item a.Link--primary')!.innerHTML.replace(/<\/?code>/g, '`') - )!.split(/\n\n/); - + const [prTitle, ...prBody] = getFirstCommitMessage(); textFieldEdit.set( select('.discussion-topic-header input')!, prTitle, ); textFieldEdit.insert( select('#new_pull_request textarea[aria-label="Comment body"]')!, - prMessage.join('\n\n'), + prBody.join('\n\n'), ); } |