From 13a4ebf4dbd6b6cbb7698b469b83e1264a41d209 Mon Sep 17 00:00:00 2001 From: Nate Smith Date: Thu, 17 Aug 2023 15:58:38 -0500 Subject: [PATCH] prompter for milestone --- pkg/cmd/pr/shared/survey.go | 21 +++++---------------- pkg/cmd/pr/shared/survey_test.go | 14 ++------------ 2 files changed, 7 insertions(+), 28 deletions(-) diff --git a/pkg/cmd/pr/shared/survey.go b/pkg/cmd/pr/shared/survey.go index 7d56c9caf..393b87757 100644 --- a/pkg/cmd/pr/shared/survey.go +++ b/pkg/cmd/pr/shared/survey.go @@ -4,11 +4,9 @@ import ( "fmt" "strings" - "github.com/AlecAivazis/survey/v2" "github.com/cli/cli/v2/api" "github.com/cli/cli/v2/internal/ghrepo" "github.com/cli/cli/v2/pkg/iostreams" - "github.com/cli/cli/v2/pkg/prompt" ) type Action int @@ -256,7 +254,6 @@ func MetadataSurvey(p Prompt, io *iostreams.IOStreams, baseRepo ghrepo.Interface fmt.Fprintln(io.ErrOut, "warning: no labels in the repository") } } - var mqs []*survey.Question if isChosen("Projects") { if len(projects) > 0 { selected, err := p.MultiSelect("Projects", state.Projects, projects) @@ -278,23 +275,15 @@ func MetadataSurvey(p Prompt, io *iostreams.IOStreams, baseRepo ghrepo.Interface } else { milestoneDefault = milestones[1] } - mqs = append(mqs, &survey.Question{ - Name: "milestone", - Prompt: &survey.Select{ - Message: "Milestone", - Options: milestones, - Default: milestoneDefault, - }, - }) + selected, err := p.Select("Milestone", milestoneDefault, milestones) + if err != nil { + return err + } + values.Milestone = milestones[selected] } else { fmt.Fprintln(io.ErrOut, "warning: no milestones in the repository") } } - //nolint:staticcheck // SA1019: prompt.SurveyAsk is deprecated: use Prompter - err = prompt.SurveyAsk(mqs, &values) - if err != nil { - return fmt.Errorf("could not prompt: %w", err) - } if isChosen("Reviewers") { var logins []string diff --git a/pkg/cmd/pr/shared/survey_test.go b/pkg/cmd/pr/shared/survey_test.go index ffc2bc55b..4653ce08b 100644 --- a/pkg/cmd/pr/shared/survey_test.go +++ b/pkg/cmd/pr/shared/survey_test.go @@ -7,7 +7,6 @@ import ( "github.com/cli/cli/v2/internal/ghrepo" "github.com/cli/cli/v2/internal/prompter" "github.com/cli/cli/v2/pkg/iostreams" - "github.com/cli/cli/v2/pkg/prompt" "github.com/stretchr/testify/assert" ) @@ -61,17 +60,8 @@ func TestMetadataSurvey_selectAll(t *testing.T) { pm.RegisterMultiSelect("Projects", []string{}, []string{"Huge Refactoring", "The road to 1.0"}, func(_ string, _, _ []string) ([]int, error) { return []int{1}, nil }) - - //nolint:staticcheck // SA1019: prompt.InitAskStubber is deprecated: use NewAskStubber - as, restoreAsk := prompt.InitAskStubber() - defer restoreAsk() - - //nolint:staticcheck // SA1019: as.Stub is deprecated: use StubPrompt - as.Stub([]*prompt.QuestionStub{ - { - Name: "milestone", - Value: "(none)", - }, + pm.RegisterSelect("Milestone", []string{"(none)", "1.2 patch release"}, func(_, _ string, _ []string) (int, error) { + return 0, nil }) state := &IssueMetadataState{