feat: make topic param as list in repo list command (#6539)

Co-authored-by: Mislav Marohnić <mislav@github.com>
This commit is contained in:
Jeffrey Duroyon 2022-11-01 19:39:43 +01:00 committed by GitHub
parent eeff8868ab
commit 6d32ce612c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 32 additions and 17 deletions

View file

@ -23,14 +23,14 @@ type FilterOptions struct {
Fork bool
Source bool
Language string
Topic string
Topic []string
Archived bool
NonArchived bool
Fields []string
}
func listRepos(client *http.Client, hostname string, limit int, owner string, filter FilterOptions) (*RepositoryList, error) {
if filter.Language != "" || filter.Archived || filter.NonArchived || filter.Topic != "" || filter.Visibility == "internal" {
if filter.Language != "" || filter.Archived || filter.NonArchived || len(filter.Topic) > 0 || filter.Visibility == "internal" {
return searchRepos(client, hostname, limit, owner, filter)
}
@ -208,7 +208,7 @@ func searchQuery(owner string, filter FilterOptions) string {
Fork: fork,
Is: []string{filter.Visibility},
Language: filter.Language,
Topic: []string{filter.Topic},
Topic: filter.Topic,
User: owner,
},
}

View file

@ -31,7 +31,7 @@ type ListOptions struct {
Fork bool
Source bool
Language string
Topic string
Topic []string
Archived bool
NonArchived bool
@ -92,7 +92,7 @@ func NewCmdList(f *cmdutil.Factory, runF func(*ListOptions) error) *cobra.Comman
cmd.Flags().BoolVar(&opts.Source, "source", false, "Show only non-forks")
cmd.Flags().BoolVar(&opts.Fork, "fork", false, "Show only forks")
cmd.Flags().StringVarP(&opts.Language, "language", "l", "", "Filter by primary coding language")
cmd.Flags().StringVar(&opts.Topic, "topic", "", "Filter by topic")
cmd.Flags().StringSliceVarP(&opts.Topic, "topic", "", nil, "Filter by topic")
cmdutil.StringEnumFlag(cmd, &opts.Visibility, "visibility", "", "", []string{"public", "private", "internal"}, "Filter by repository visibility")
cmd.Flags().BoolVar(&opts.Archived, "archived", false, "Show only archived repositories")
cmd.Flags().BoolVar(&opts.NonArchived, "no-archived", false, "Omit archived repositories")
@ -195,7 +195,7 @@ func listRun(opts *ListOptions) error {
fmt.Fprintln(opts.IO.ErrOut, "warning: this query uses the Search API which is capped at 1000 results maximum")
}
if opts.IO.IsStdoutTTY() {
hasFilters := filter.Visibility != "" || filter.Fork || filter.Source || filter.Language != "" || filter.Topic != ""
hasFilters := filter.Visibility != "" || filter.Fork || filter.Source || filter.Language != "" || len(filter.Topic) > 0
title := listHeader(listResult.Owner, len(listResult.Repositories), listResult.TotalCount, hasFilters)
fmt.Fprintf(opts.IO.Out, "\n%s\n\n", title)
}

View file

@ -38,7 +38,7 @@ func TestNewCmdList(t *testing.T) {
Fork: false,
Source: false,
Language: "",
Topic: "",
Topic: []string(nil),
Archived: false,
NonArchived: false,
},
@ -53,7 +53,7 @@ func TestNewCmdList(t *testing.T) {
Fork: false,
Source: false,
Language: "",
Topic: "",
Topic: []string(nil),
Archived: false,
NonArchived: false,
},
@ -68,7 +68,7 @@ func TestNewCmdList(t *testing.T) {
Fork: false,
Source: false,
Language: "",
Topic: "",
Topic: []string(nil),
Archived: false,
NonArchived: false,
},
@ -83,7 +83,7 @@ func TestNewCmdList(t *testing.T) {
Fork: false,
Source: false,
Language: "",
Topic: "",
Topic: []string(nil),
Archived: false,
NonArchived: false,
},
@ -98,7 +98,7 @@ func TestNewCmdList(t *testing.T) {
Fork: false,
Source: false,
Language: "",
Topic: "",
Topic: []string(nil),
Archived: false,
NonArchived: false,
},
@ -113,7 +113,7 @@ func TestNewCmdList(t *testing.T) {
Fork: true,
Source: false,
Language: "",
Topic: "",
Topic: []string(nil),
Archived: false,
NonArchived: false,
},
@ -128,7 +128,7 @@ func TestNewCmdList(t *testing.T) {
Fork: false,
Source: true,
Language: "",
Topic: "",
Topic: []string(nil),
Archived: false,
NonArchived: false,
},
@ -143,7 +143,7 @@ func TestNewCmdList(t *testing.T) {
Fork: false,
Source: false,
Language: "go",
Topic: "",
Topic: []string(nil),
Archived: false,
NonArchived: false,
},
@ -158,7 +158,7 @@ func TestNewCmdList(t *testing.T) {
Fork: false,
Source: false,
Language: "",
Topic: "",
Topic: []string(nil),
Archived: true,
NonArchived: false,
},
@ -173,7 +173,7 @@ func TestNewCmdList(t *testing.T) {
Fork: false,
Source: false,
Language: "",
Topic: "",
Topic: []string(nil),
Archived: false,
NonArchived: true,
},
@ -188,7 +188,22 @@ func TestNewCmdList(t *testing.T) {
Fork: false,
Source: false,
Language: "",
Topic: "cli",
Topic: []string{"cli"},
Archived: false,
NonArchived: false,
},
},
{
name: "with multiple topic",
cli: "--topic cli --topic multiple-topic",
wants: ListOptions{
Limit: 30,
Owner: "",
Visibility: "",
Fork: false,
Source: false,
Language: "",
Topic: []string{"cli", "multiple-topic"},
Archived: false,
NonArchived: false,
},