prompter for milestone

This commit is contained in:
Nate Smith 2023-08-17 15:58:38 -05:00
parent 00c25a8d62
commit 13a4ebf4db
2 changed files with 7 additions and 28 deletions

View file

@ -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

View file

@ -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{