diff --git a/pkg/cmd/pr/shared/survey.go b/pkg/cmd/pr/shared/survey.go index 60a93d812..374d99f55 100644 --- a/pkg/cmd/pr/shared/survey.go +++ b/pkg/cmd/pr/shared/survey.go @@ -210,22 +210,28 @@ func MetadataSurvey(p Prompt, io *iostreams.IOStreams, baseRepo ghrepo.Interface milestones = append(milestones, m.Title) } - var mqs []*survey.Question + values := struct { + Reviewers []string + Assignees []string + Labels []string + Projects []string + Milestone string + }{} + if isChosen("Reviewers") { if len(reviewers) > 0 { - mqs = append(mqs, &survey.Question{ - Name: "reviewers", - Prompt: &survey.MultiSelect{ - Message: "Reviewers", - Options: reviewers, - Default: state.Reviewers, - Filter: prompter.LatinMatchingFilter, - }, - }) + selected, err := p.MultiSelect("Reviewers", state.Reviewers, reviewers) + if err != nil { + return err + } + for _, i := range selected { + values.Reviewers = append(values.Reviewers, reviewers[i]) + } } else { fmt.Fprintln(io.ErrOut, "warning: no available reviewers") } } + var mqs []*survey.Question if isChosen("Assignees") { if len(assignees) > 0 { mqs = append(mqs, &survey.Question{ @@ -291,15 +297,6 @@ func MetadataSurvey(p Prompt, io *iostreams.IOStreams, baseRepo ghrepo.Interface fmt.Fprintln(io.ErrOut, "warning: no milestones in the repository") } } - - values := struct { - Reviewers []string - Assignees []string - Labels []string - Projects []string - Milestone string - }{} - //nolint:staticcheck // SA1019: prompt.SurveyAsk is deprecated: use Prompter err = prompt.SurveyAsk(mqs, &values) if err != nil { diff --git a/pkg/cmd/pr/shared/survey_test.go b/pkg/cmd/pr/shared/survey_test.go index 88ca4d510..8f19540fc 100644 --- a/pkg/cmd/pr/shared/survey_test.go +++ b/pkg/cmd/pr/shared/survey_test.go @@ -47,9 +47,11 @@ func TestMetadataSurvey_selectAll(t *testing.T) { pm := prompter.NewMockPrompter(t) pm.RegisterMultiSelect("What would you like to add?", []string{}, []string{"Reviewers", "Assignees", "Labels", "Projects", "Milestone"}, func(_ string, _, _ []string) ([]int, error) { - // []string{"Labels", "Projects", "Assignees", "Reviewers", "Milestone"}, return []int{0, 1, 2, 3, 4}, nil }) + pm.RegisterMultiSelect("Reviewers", []string{}, []string{"hubot", "monalisa"}, func(_ string, _, _ []string) ([]int, error) { + return []int{1}, nil + }) //nolint:staticcheck // SA1019: prompt.InitAskStubber is deprecated: use NewAskStubber as, restoreAsk := prompt.InitAskStubber() @@ -57,10 +59,10 @@ func TestMetadataSurvey_selectAll(t *testing.T) { //nolint:staticcheck // SA1019: as.Stub is deprecated: use StubPrompt as.Stub([]*prompt.QuestionStub{ - { - Name: "reviewers", - Value: []string{"monalisa"}, - }, + //{ + // Name: "reviewers", + // Value: []string{"monalisa"}, + //}, { Name: "assignees", Value: []string{"hubot"}, @@ -115,10 +117,8 @@ func TestMetadataSurvey_keepExisting(t *testing.T) { } pm := prompter.NewMockPrompter(t) - pm.RegisterMultiSelect("What would you like to add?", []string{}, []string{"Assignees", "Labels", "Projects", "Milestone"}, func(_ string, _, _ []string) ([]int, error) { return []int{1, 2}, nil - }) //nolint:staticcheck // SA1019: prompt.InitAskStubber is deprecated: use NewAskStubber