summaryrefslogtreecommitdiff
path: root/source/features/use-first-commit-message-for-new-prs.tsx
diff options
context:
space:
mode:
authorGravatar yakov116 <16872793+yakov116@users.noreply.github.com> 2020-07-23 06:47:39 -0400
committerGravatar GitHub <noreply@github.com> 2020-07-23 11:47:39 +0100
commita82f849bd4a745542642b9453c12a6ec18c381aa (patch)
tree1dbfe76ab55b97fa9dc43f5e9eecf65dca133521 /source/features/use-first-commit-message-for-new-prs.tsx
parentb380fd5902e9cbb6854c645319ddbdbb56bad56b (diff)
downloadrefined-github-a82f849bd4a745542642b9453c12a6ec18c381aa.tar.gz
refined-github-a82f849bd4a745542642b9453c12a6ec18c381aa.tar.zst
refined-github-a82f849bd4a745542642b9453c12a6ec18c381aa.zip
Add `use-first-commit-message-for-new-prs` feature (#3342)
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.tsx41
1 files changed, 41 insertions, 0 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
new file mode 100644
index 00000000..bbca4de5
--- /dev/null
+++ b/source/features/use-first-commit-message-for-new-prs.tsx
@@ -0,0 +1,41 @@
+import select from 'select-dom';
+import elementReady from 'element-ready';
+import * as pageDetect from 'github-url-detection';
+import * as textFieldEdit from 'text-field-edit';
+
+import features from '.';
+import looseParseInt from '../helpers/loose-parse-int';
+
+async function init(): Promise<void | false> {
+ const commitCount = await elementReady<HTMLElement>([
+ '.overall-summary > ul > li:nth-child(1) .text-emphasized', // Cross fork
+ '[href="#commits_bucket"] .Counter' // Same repository
+ ].join());
+
+ if (!commitCount || looseParseInt(commitCount.textContent!) < 2 || !select.exists('#new_pull_request')) {
+ return false;
+ }
+
+ const [prTitle, ...prMessage] = select('#commits_bucket .commit-message code a')!.title.split(/\n\n/);
+
+ textFieldEdit.set(
+ select<HTMLInputElement>('.discussion-topic-header input')!,
+ prTitle
+ );
+ textFieldEdit.insert(
+ select<HTMLTextAreaElement>('#new_pull_request textArea[aria-label="Comment body"]')!,
+ prMessage.join('\n\n')
+ );
+}
+
+void features.add({
+ id: __filebasename,
+ description: 'Use the first commit for a new PR’s title and description.',
+ screenshot: 'https://user-images.githubusercontent.com/16872793/87246205-ccf42400-c419-11ea-86d5-0e6570d99e6e.gif'
+}, {
+ include: [
+ pageDetect.isCompare
+ ],
+ waitForDomReady: false,
+ init
+});