@@ -146,26 +146,9 @@ func createRun(opts *CreateOptions) (err error) {
146146
147147 client := ctx .Client
148148
149- var milestoneTitles []string
150- if opts .Milestone != "" {
151- milestoneTitles = []string {opts .Milestone }
152- }
153-
154- state := shared.IssueMetadataState {
155- Type : shared .PRMetadata ,
156- Reviewers : opts .Reviewers ,
157- Assignees : opts .Assignees ,
158- Labels : opts .Labels ,
159- Projects : opts .Projects ,
160- Milestones : milestoneTitles ,
161- }
162-
163- var defaultsErr error
164- if opts .Autofill || ! opts .TitleProvided || ! opts .BodyProvided {
165- defaultsErr = computeDefaults (* ctx , & state )
166- if defaultsErr != nil {
167- return fmt .Errorf ("could not compute title or body defaults: %w" , defaultsErr )
168- }
149+ state , err := NewIssueState (* ctx , * opts )
150+ if err != nil {
151+ return err
169152 }
170153
171154 if opts .WebMode {
@@ -177,7 +160,7 @@ func createRun(opts *CreateOptions) (err error) {
177160 if err != nil {
178161 return err
179162 }
180- return previewPR (* opts , * ctx , state )
163+ return previewPR (* opts , * ctx , * state )
181164 }
182165
183166 if opts .TitleProvided {
@@ -211,22 +194,18 @@ func createRun(opts *CreateOptions) (err error) {
211194 cs .Cyan (ctx .HeadBranchLabel ),
212195 cs .Cyan (ctx .BaseBranch ),
213196 ghrepo .FullName (ctx .BaseRepo ))
214- if (state .Title == "" || state .Body == "" ) && defaultsErr != nil {
215- fmt .Fprintf (opts .IO .ErrOut ,
216- "%s warning: could not compute title or body defaults: %s\n " , cs .Yellow ("!" ), defaultsErr )
217- }
218197 }
219198
220199 if opts .Autofill || (opts .TitleProvided && opts .BodyProvided ) {
221200 err = handlePush (* opts , * ctx )
222201 if err != nil {
223202 return err
224203 }
225- return submitPR (* opts , * ctx , state )
204+ return submitPR (* opts , * ctx , * state )
226205 }
227206
228207 if ! opts .TitleProvided {
229- err = shared .TitleSurvey (& state )
208+ err = shared .TitleSurvey (state )
230209 if err != nil {
231210 return err
232211 }
@@ -241,12 +220,12 @@ func createRun(opts *CreateOptions) (err error) {
241220 if ! opts .BodyProvided {
242221 templateFiles , legacyTemplate := shared .FindTemplates (opts .RootDirOverride , "PULL_REQUEST_TEMPLATE" )
243222
244- templateContent , err = shared .TemplateSurvey (templateFiles , legacyTemplate , state )
223+ templateContent , err = shared .TemplateSurvey (templateFiles , legacyTemplate , * state )
245224 if err != nil {
246225 return err
247226 }
248227
249- err = shared .BodySurvey (& state , templateContent , editorCommand )
228+ err = shared .BodySurvey (state , templateContent , editorCommand )
250229 if err != nil {
251230 return err
252231 }
@@ -263,7 +242,7 @@ func createRun(opts *CreateOptions) (err error) {
263242 }
264243
265244 if action == shared .MetadataAction {
266- err = shared .MetadataSurvey (opts .IO , client , ctx .BaseRepo , & state )
245+ err = shared .MetadataSurvey (opts .IO , client , ctx .BaseRepo , state )
267246 if err != nil {
268247 return err
269248 }
@@ -285,17 +264,17 @@ func createRun(opts *CreateOptions) (err error) {
285264 }
286265
287266 if action == shared .PreviewAction {
288- return previewPR (* opts , * ctx , state )
267+ return previewPR (* opts , * ctx , * state )
289268 }
290269
291270 if action == shared .SubmitAction {
292- return submitPR (* opts , * ctx , state )
271+ return submitPR (* opts , * ctx , * state )
293272 }
294273
295274 return errors .New ("expected to cancel, preview, or submit" )
296275}
297276
298- func computeDefaults (ctx CreateContext , state * shared.IssueMetadataState ) error {
277+ func initDefaultTitleBody (ctx CreateContext , state * shared.IssueMetadataState ) error {
299278 baseRef := ctx .BaseTrackingBranch
300279 headRef := ctx .HeadBranch
301280
@@ -365,6 +344,31 @@ func determineTrackingBranch(remotes context.Remotes, headBranch string) *git.Tr
365344 return nil
366345}
367346
347+ func NewIssueState (ctx CreateContext , opts CreateOptions ) (* shared.IssueMetadataState , error ) {
348+ var milestoneTitles []string
349+ if opts .Milestone != "" {
350+ milestoneTitles = []string {opts .Milestone }
351+ }
352+
353+ state := & shared.IssueMetadataState {
354+ Type : shared .PRMetadata ,
355+ Reviewers : opts .Reviewers ,
356+ Assignees : opts .Assignees ,
357+ Labels : opts .Labels ,
358+ Projects : opts .Projects ,
359+ Milestones : milestoneTitles ,
360+ }
361+
362+ if opts .Autofill || ! opts .TitleProvided || ! opts .BodyProvided {
363+ err := initDefaultTitleBody (ctx , state )
364+ if err != nil {
365+ return nil , fmt .Errorf ("could not compute title or body defaults: %w" , err )
366+ }
367+ }
368+
369+ return state , nil
370+ }
371+
368372func NewCreateContext (opts * CreateOptions ) (* CreateContext , error ) {
369373 httpClient , err := opts .HttpClient ()
370374 if err != nil {
0 commit comments