use prompter for labels

This commit is contained in:
Nate Smith 2023-08-17 15:50:55 -05:00
parent 9b7cc44c7f
commit 81cbf5e9b6
2 changed files with 14 additions and 18 deletions

View file

@ -244,22 +244,20 @@ func MetadataSurvey(p Prompt, io *iostreams.IOStreams, baseRepo ghrepo.Interface
fmt.Fprintln(io.ErrOut, "warning: no assignable users")
}
}
var mqs []*survey.Question
if isChosen("Labels") {
if len(labels) > 0 {
mqs = append(mqs, &survey.Question{
Name: "labels",
Prompt: &survey.MultiSelect{
Message: "Labels",
Options: labels,
Default: state.Labels,
Filter: prompter.LatinMatchingFilter,
},
})
selected, err := p.MultiSelect("Labels", state.Labels, labels)
if err != nil {
return err
}
for _, i := range selected {
values.Labels = append(values.Labels, labels[i])
}
} else {
fmt.Fprintln(io.ErrOut, "warning: no labels in the repository")
}
}
var mqs []*survey.Question
if isChosen("Projects") {
if len(projects) > 0 {
mqs = append(mqs, &survey.Question{

View file

@ -55,6 +55,9 @@ func TestMetadataSurvey_selectAll(t *testing.T) {
pm.RegisterMultiSelect("Assignees", []string{}, []string{"hubot", "monalisa"}, func(_ string, _, _ []string) ([]int, error) {
return []int{0}, nil
})
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()
@ -62,10 +65,6 @@ func TestMetadataSurvey_selectAll(t *testing.T) {
//nolint:staticcheck // SA1019: as.Stub is deprecated: use StubPrompt
as.Stub([]*prompt.QuestionStub{
{
Name: "labels",
Value: []string{"good first issue"},
},
{
Name: "projects",
Value: []string{"The road to 1.0"},
@ -115,6 +114,9 @@ func TestMetadataSurvey_keepExisting(t *testing.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
})
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()
@ -122,10 +124,6 @@ func TestMetadataSurvey_keepExisting(t *testing.T) {
//nolint:staticcheck // SA1019: as.Stub is deprecated: use StubPrompt
as.Stub([]*prompt.QuestionStub{
{
Name: "labels",
Value: []string{"good first issue"},
},
{
Name: "projects",
Value: []string{"The road to 1.0"},