Skip to content

Commit

Permalink
prompter for projects
Browse files Browse the repository at this point in the history
  • Loading branch information
Nate Smith committed Aug 17, 2023
1 parent 81cbf5e commit 00c25a8
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 25 deletions.
17 changes: 7 additions & 10 deletions pkg/cmd/pr/shared/survey.go
Expand Up @@ -7,7 +7,6 @@ import (
"github.com/AlecAivazis/survey/v2"
"github.com/cli/cli/v2/api"
"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"
)
Expand Down Expand Up @@ -260,15 +259,13 @@ func MetadataSurvey(p Prompt, io *iostreams.IOStreams, baseRepo ghrepo.Interface
var mqs []*survey.Question
if isChosen("Projects") {
if len(projects) > 0 {
mqs = append(mqs, &survey.Question{
Name: "projects",
Prompt: &survey.MultiSelect{
Message: "Projects",
Options: projects,
Default: state.Projects,
Filter: prompter.LatinMatchingFilter,
},
})
selected, err := p.MultiSelect("Projects", state.Projects, projects)
if err != nil {
return err
}
for _, i := range selected {
values.Projects = append(values.Projects, projects[i])
}
} else {
fmt.Fprintln(io.ErrOut, "warning: no projects to choose from")
}
Expand Down
20 changes: 5 additions & 15 deletions pkg/cmd/pr/shared/survey_test.go
Expand Up @@ -58,17 +58,16 @@ func TestMetadataSurvey_selectAll(t *testing.T) {
pm.RegisterMultiSelect("Labels", []string{}, []string{"help wanted", "good first issue"}, func(_ string, _, _ []string) ([]int, error) {
return []int{1}, nil
})
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: "projects",
Value: []string{"The road to 1.0"},
},
{
Name: "milestone",
Value: "(none)",
Expand Down Expand Up @@ -117,17 +116,8 @@ func TestMetadataSurvey_keepExisting(t *testing.T) {
pm.RegisterMultiSelect("Labels", []string{}, []string{"help wanted", "good first issue"}, 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: "projects",
Value: []string{"The road to 1.0"},
},
pm.RegisterMultiSelect("Projects", []string{}, []string{"Huge Refactoring", "The road to 1.0"}, func(_ string, _, _ []string) ([]int, error) {
return []int{1}, nil
})

state := &IssueMetadataState{
Expand Down

0 comments on commit 00c25a8

Please sign in to comment.