Skip to content
This repository was archived by the owner on Nov 4, 2022. It is now read-only.

Commit 68c55b1

Browse files
author
Ryan Garant
committed
feat(pull-request): open editor when description is empty
This will open user's editor when they submit a new pr and leave the --description or --title empty re #34
1 parent 6892014 commit 68c55b1

File tree

1 file changed

+25
-10
lines changed

1 file changed

+25
-10
lines changed

src/cmds/pull-request.ts

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import { startsWith } from 'lodash'
1111
import * as marked from 'marked'
1212
import { produce } from 'immer'
1313
import * as TerminalRenderer from 'marked-terminal'
14-
import { openUrl, userRanValidFlags } from '../utils'
14+
import { openUrl, userRanValidFlags, userLeftMsgEmpty, openFileInEditor } from '../utils'
1515
import * as wrap from 'wordwrap'
1616
import * as git from '../git'
1717

@@ -821,35 +821,50 @@ function sortPullsByComplexity_(pulls, direction) {
821821
}
822822

823823
async function submit(options, user) {
824+
let description = options.description
825+
let title = options.title
824826
let pullBranch = options.pullBranch || options.currentBranch
825827

826828
if (testing) {
827829
pullBranch = 'test'
828830
}
829831

830-
git.push(options.config.default_remote, pullBranch)
832+
if (userLeftMsgEmpty(title)) {
833+
title = openFileInEditor(
834+
'temp-gh-pr-title.txt',
835+
`# Add a issue title message on the next line\n${git.getLastCommitMessage(pullBranch)}`
836+
)
837+
}
838+
839+
// If user passes an empty title and description, --description will get merged into options.title
840+
// Need to reference the original title not the potentially modified one
841+
if (userLeftMsgEmpty(options.title) || userLeftMsgEmpty(description)) {
842+
description = openFileInEditor(
843+
'temp-gh-pr-body.md',
844+
'<!-- Add an pr body message in markdown format below -->'
845+
)
846+
}
831847

832-
var payload: any = {
848+
const payload: any = {
833849
mediaType: {
834850
previews: ['shadow-cat'],
835851
},
836852
owner: user,
837853
base: options.branch,
838854
head: `${options.user}:${pullBranch}`,
839855
repo: options.repo,
856+
title: title,
857+
...(options.issue ? { issue: options.issue } : {}),
840858
...(options.draft ? { draft: options.draft } : {}),
841859
...(options.description ? { body: options.description } : {}),
842860
}
843861

844862
try {
845-
if (options.issue) {
846-
payload.issue = options.issue
847-
var { data } = await options.GitHub.pulls.createFromIssue(payload)
848-
} else {
849-
payload.title = options.title || git.getLastCommitMessage(pullBranch)
863+
git.push(options.config.default_remote, pullBranch)
850864

851-
var { data } = await options.GitHub.pulls.create(payload)
852-
}
865+
const method = payload.issue ? 'createFromIssue' : 'create'
866+
867+
var { data } = await options.GitHub.pulls[method](payload)
853868
} catch (err) {
854869
var { originalError, pull } = await checkPullRequestIntegrity_(options, err)
855870

0 commit comments

Comments
 (0)