summaryrefslogtreecommitdiff
path: root/source/features/use-first-commit-message-for-new-prs.tsx
diff options
context:
space:
mode:
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
+});