@@ -32,8 +32,7 @@ type MergeOptions struct {
3232 DeleteBranch bool
3333 MergeMethod api.PullRequestMergeMethod
3434
35- Body string
36- BodyProvided bool
35+ Body string
3736
3837 IsDeleteBranchIndicated bool
3938 CanDeleteLocalBranch bool
@@ -99,10 +98,6 @@ func NewCmdMerge(f *cmdutil.Factory, runF func(*MergeOptions) error) *cobra.Comm
9998 opts .IsDeleteBranchIndicated = cmd .Flags ().Changed ("delete-branch" )
10099 opts .CanDeleteLocalBranch = ! cmd .Flags ().Changed ("repo" )
101100
102- if cmd .Flags ().Changed ("body" ) {
103- opts .BodyProvided = true
104- }
105-
106101 if runF != nil {
107102 return runF (opts )
108103 }
@@ -169,7 +164,7 @@ func mergeRun(opts *MergeOptions) error {
169164 return err
170165 }
171166
172- allowEditMsg := ( mergeMethod != api .PullRequestMergeMethodRebase ) && ! opts . BodyProvided
167+ allowEditMsg := mergeMethod != api .PullRequestMergeMethodRebase
173168
174169 action , err := confirmSurvey (allowEditMsg )
175170 if err != nil {
@@ -183,12 +178,19 @@ func mergeRun(opts *MergeOptions) error {
183178 return err
184179 }
185180
186- msg , err := commitMsgSurvey (editorCommand )
181+ if opts .Body == "" {
182+ if mergeMethod == api .PullRequestMergeMethodMerge {
183+ opts .Body = pr .Title
184+ } else {
185+ opts .Body = pr .ViewerMergeBodyText
186+ }
187+ }
188+
189+ msg , err := commitMsgSurvey (opts .Body , editorCommand )
187190 if err != nil {
188191 return err
189192 }
190193 opts .Body = msg
191- opts .BodyProvided = true
192194
193195 action , err = confirmSurvey (false )
194196 if err != nil {
@@ -202,7 +204,7 @@ func mergeRun(opts *MergeOptions) error {
202204 }
203205
204206 var body * string
205- if opts .BodyProvided {
207+ if opts .Body != "" {
206208 body = & opts .Body
207209 }
208210
@@ -378,13 +380,15 @@ func confirmSurvey(allowEditMsg bool) (shared.Action, error) {
378380 }
379381}
380382
381- func commitMsgSurvey (editorCommand string ) (string , error ) {
383+ func commitMsgSurvey (msg string , editorCommand string ) (string , error ) {
382384 var result string
383385 q := & surveyext.GhEditor {
384386 EditorCommand : editorCommand ,
385387 Editor : & survey.Editor {
386- Message : "Body" ,
387- FileName : "*.md" ,
388+ Message : "Body" ,
389+ AppendDefault : true ,
390+ Default : msg ,
391+ FileName : "*.md" ,
388392 },
389393 }
390394 err := prompt .SurveyAskOne (q , & result )
0 commit comments