@@ -508,11 +508,7 @@ func issueCreate(cmd *cobra.Command, args []string) error {
508508 if isWeb , err := cmd .Flags ().GetBool ("web" ); err == nil && isWeb {
509509 openURL := ghrepo .GenerateRepoURL (baseRepo , "issues/new" )
510510 if title != "" || body != "" {
511- milestone := ""
512- if len (milestoneTitles ) > 0 {
513- milestone = milestoneTitles [0 ]
514- }
515- openURL , err = withPrAndIssueQueryParams (openURL , title , body , assignees , labelNames , projectNames , milestone )
511+ openURL , err = shared .WithPrAndIssueQueryParams (openURL , title , body , assignees , labelNames , projectNames , milestoneTitles )
516512 if err != nil {
517513 return err
518514 }
@@ -535,9 +531,9 @@ func issueCreate(cmd *cobra.Command, args []string) error {
535531 return fmt .Errorf ("the '%s' repository has disabled issues" , ghrepo .FullName (baseRepo ))
536532 }
537533
538- action := SubmitAction
539- tb := issueMetadataState {
540- Type : issueMetadata ,
534+ action := shared . SubmitAction
535+ tb := shared. IssueMetadataState {
536+ Type : shared . IssueMetadata ,
541537 Assignees : assignees ,
542538 Labels : labelNames ,
543539 Projects : projectNames ,
@@ -558,14 +554,20 @@ func issueCreate(cmd *cobra.Command, args []string) error {
558554 legacyTemplateFile = githubtemplate .FindLegacy (rootDir , "ISSUE_TEMPLATE" )
559555 }
560556 }
561- err := titleBodySurvey (cmd , & tb , apiClient , baseRepo , title , body , defaults {}, nonLegacyTemplateFiles , legacyTemplateFile , false , repo .ViewerCanTriage ())
557+
558+ editorCommand , err := cmdutil .DetermineEditor (ctx .Config )
559+ if err != nil {
560+ return err
561+ }
562+
563+ err = shared .TitleBodySurvey (defaultStreams , editorCommand , & tb , apiClient , baseRepo , title , body , shared.Defaults {}, nonLegacyTemplateFiles , legacyTemplateFile , false , repo .ViewerCanTriage ())
562564 if err != nil {
563565 return fmt .Errorf ("could not collect title and/or body: %w" , err )
564566 }
565567
566568 action = tb .Action
567569
568- if tb .Action == CancelAction {
570+ if tb .Action == shared . CancelAction {
569571 fmt .Fprintln (cmd .ErrOrStderr (), "Discarding." )
570572
571573 return nil
@@ -583,26 +585,22 @@ func issueCreate(cmd *cobra.Command, args []string) error {
583585 }
584586 }
585587
586- if action == PreviewAction {
588+ if action == shared . PreviewAction {
587589 openURL := ghrepo .GenerateRepoURL (baseRepo , "issues/new" )
588- milestone := ""
589- if len (milestoneTitles ) > 0 {
590- milestone = milestoneTitles [0 ]
591- }
592- openURL , err = withPrAndIssueQueryParams (openURL , title , body , assignees , labelNames , projectNames , milestone )
590+ openURL , err = shared .WithPrAndIssueQueryParams (openURL , title , body , assignees , labelNames , projectNames , milestoneTitles )
593591 if err != nil {
594592 return err
595593 }
596594 // TODO could exceed max url length for explorer
597595 fmt .Fprintf (cmd .ErrOrStderr (), "Opening %s in your browser.\n " , utils .DisplayURL (openURL ))
598596 return utils .OpenInBrowser (openURL )
599- } else if action == SubmitAction {
597+ } else if action == shared . SubmitAction {
600598 params := map [string ]interface {}{
601599 "title" : title ,
602600 "body" : body ,
603601 }
604602
605- err = addMetadataToIssueParams (apiClient , baseRepo , params , & tb )
603+ err = shared . AddMetadataToIssueParams (apiClient , baseRepo , params , & tb )
606604 if err != nil {
607605 return err
608606 }
@@ -620,82 +618,6 @@ func issueCreate(cmd *cobra.Command, args []string) error {
620618 return nil
621619}
622620
623- func addMetadataToIssueParams (client * api.Client , baseRepo ghrepo.Interface , params map [string ]interface {}, tb * issueMetadataState ) error {
624- if ! tb .HasMetadata () {
625- return nil
626- }
627-
628- if tb .MetadataResult == nil {
629- resolveInput := api.RepoResolveInput {
630- Reviewers : tb .Reviewers ,
631- Assignees : tb .Assignees ,
632- Labels : tb .Labels ,
633- Projects : tb .Projects ,
634- Milestones : tb .Milestones ,
635- }
636-
637- var err error
638- tb .MetadataResult , err = api .RepoResolveMetadataIDs (client , baseRepo , resolveInput )
639- if err != nil {
640- return err
641- }
642- }
643-
644- assigneeIDs , err := tb .MetadataResult .MembersToIDs (tb .Assignees )
645- if err != nil {
646- return fmt .Errorf ("could not assign user: %w" , err )
647- }
648- params ["assigneeIds" ] = assigneeIDs
649-
650- labelIDs , err := tb .MetadataResult .LabelsToIDs (tb .Labels )
651- if err != nil {
652- return fmt .Errorf ("could not add label: %w" , err )
653- }
654- params ["labelIds" ] = labelIDs
655-
656- projectIDs , err := tb .MetadataResult .ProjectsToIDs (tb .Projects )
657- if err != nil {
658- return fmt .Errorf ("could not add to project: %w" , err )
659- }
660- params ["projectIds" ] = projectIDs
661-
662- if len (tb .Milestones ) > 0 {
663- milestoneID , err := tb .MetadataResult .MilestoneToID (tb .Milestones [0 ])
664- if err != nil {
665- return fmt .Errorf ("could not add to milestone '%s': %w" , tb .Milestones [0 ], err )
666- }
667- params ["milestoneId" ] = milestoneID
668- }
669-
670- if len (tb .Reviewers ) == 0 {
671- return nil
672- }
673-
674- var userReviewers []string
675- var teamReviewers []string
676- for _ , r := range tb .Reviewers {
677- if strings .ContainsRune (r , '/' ) {
678- teamReviewers = append (teamReviewers , r )
679- } else {
680- userReviewers = append (userReviewers , r )
681- }
682- }
683-
684- userReviewerIDs , err := tb .MetadataResult .MembersToIDs (userReviewers )
685- if err != nil {
686- return fmt .Errorf ("could not request reviewer: %w" , err )
687- }
688- params ["userReviewerIds" ] = userReviewerIDs
689-
690- teamReviewerIDs , err := tb .MetadataResult .TeamsToIDs (teamReviewers )
691- if err != nil {
692- return fmt .Errorf ("could not request reviewer: %w" , err )
693- }
694- params ["teamReviewerIds" ] = teamReviewerIDs
695-
696- return nil
697- }
698-
699621func printIssues (w io.Writer , prefix string , totalCount int , issues []api.Issue ) {
700622 table := utils .NewTablePrinter (w )
701623 for _ , issue := range issues {
0 commit comments