Skip to content

Commit

Permalink
prompter for milestone
Browse files Browse the repository at this point in the history
  • Loading branch information
Nate Smith committed Aug 17, 2023
1 parent 00c25a8 commit 13a4ebf
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 28 deletions.
21 changes: 5 additions & 16 deletions pkg/cmd/pr/shared/survey.go
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand All @@ -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
Expand Down
14 changes: 2 additions & 12 deletions pkg/cmd/pr/shared/survey_test.go
Expand Up @@ -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"
)

Expand Down Expand Up @@ -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{
Expand Down

0 comments on commit 13a4ebf

Please sign in to comment.