import prompts from 'prompts' ; import { KilledError } from '../../lib/errors' ; import { getSingleCommitOnBranch } from '../../lib/utils' ; import Branch from '../../wrapper-classes/branch' ; export async function getPRTitle ( args ) { let title = inferPRTitle ( args . branch ) ; if ( args . editPRFieldsInline ) { const response = await prompts ( { type : 'text' , name : 'title' , message : 'Title' , initial : title , } , { onCancel : ( ) => { throw new KilledError ( ) ; } , } ) ; title = response . title ?? title ; } return title ; } export function inferPRTitle ( branch ) { const priorSubmitTitle = branch . getPriorSubmitTitle ( ) ; if ( priorSubmitTitle !== undefined ) { return priorSubmitTitle ; } const singleCommit = getSingleCommitOnBranch ( branch ) ; const singleCommitSubject = singleCommit === null ? null : singleCommit . messageSubject ( ) . trim ( ) ; if ( singleCommitSubject !== null && singleCommitSubject . length > 0 ) { return singleCommitSubject ; } return `Merge ${ branch . name } into ${ branch . getParentFromMeta ( ) ! . name }` ; }