@@ -11,7 +11,7 @@ import { startsWith } from 'lodash'
1111import * as marked from 'marked'
1212import { produce } from 'immer'
1313import * as TerminalRenderer from 'marked-terminal'
14- import { openUrl , userRanValidFlags } from '../utils'
14+ import { openUrl , userRanValidFlags , userLeftMsgEmpty , openFileInEditor } from '../utils'
1515import * as wrap from 'wordwrap'
1616import * as git from '../git'
1717
@@ -821,35 +821,50 @@ function sortPullsByComplexity_(pulls, direction) {
821821}
822822
823823async 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