Merge pull request #5939 from pxeger/5934
Strip whitespace when adding topics
This commit is contained in:
commit
7b7929bb6b
2 changed files with 10 additions and 2 deletions
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue