diff --git a/pkg/cmd/repo/edit/edit.go b/pkg/cmd/repo/edit/edit.go index ae67cbadb..538a507db 100644 --- a/pkg/cmd/repo/edit/edit.go +++ b/pkg/cmd/repo/edit/edit.go @@ -326,7 +326,7 @@ func interactiveRepoEdit(opts *EditOptions, r *api.Repository) error { return err } if len(strings.TrimSpace(addTopics)) > 0 { - opts.AddTopics = strings.Split(addTopics, ",") + opts.AddTopics = parseTopics(addTopics) } if len(opts.topicsCache) > 0 { @@ -454,6 +454,14 @@ func interactiveRepoEdit(opts *EditOptions, r *api.Repository) error { return nil } +func parseTopics(s string) []string { + topics := strings.Split(s, ",") + for i, topic := range topics { + topics[i] = strings.TrimSpace(topic) + } + return topics +} + func getTopics(ctx context.Context, httpClient *http.Client, repo ghrepo.Interface) ([]string, error) { apiPath := fmt.Sprintf("repos/%s/%s/topics", repo.RepoOwner(), repo.RepoName()) req, err := http.NewRequestWithContext(ctx, "GET", ghinstance.RESTPrefix(repo.RepoHost())+apiPath, nil) diff --git a/pkg/cmd/repo/edit/edit_test.go b/pkg/cmd/repo/edit/edit_test.go index 76fbed125..dc4198581 100644 --- a/pkg/cmd/repo/edit/edit_test.go +++ b/pkg/cmd/repo/edit/edit_test.go @@ -215,7 +215,7 @@ func Test_editRun_interactive(t *testing.T) { askStubs: func(as *prompt.AskStubber) { as.StubPrompt("What do you want to edit?").AnswerWith([]string{"Description", "Topics"}) as.StubPrompt("Description of the repository").AnswerWith("awesome repo description") - as.StubPrompt("Add topics?(csv format)").AnswerWith("a,b,c,d") + as.StubPrompt("Add topics?(csv format)").AnswerWith("a, b,c,d ") as.StubPrompt("Remove Topics").AnswerWith([]string{"x"}) }, httpStubs: func(t *testing.T, reg *httpmock.Registry) {