From 2fa8a85813a89e15c6e52d4a2537e6434cffaf1e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mislav=20Marohni=C4=87?= Date: Wed, 24 Mar 2021 18:11:21 +0100 Subject: [PATCH] Unify checking whether search filters were passed by the user --- pkg/cmd/issue/list/list.go | 6 +++--- pkg/cmd/pr/list/list.go | 3 +-- pkg/cmd/pr/shared/params.go | 28 ++++++++++++++++++++++++++++ 3 files changed, 32 insertions(+), 5 deletions(-) diff --git a/pkg/cmd/issue/list/list.go b/pkg/cmd/issue/list/list.go index 88fe2fecf..d0c2430e8 100644 --- a/pkg/cmd/issue/list/list.go +++ b/pkg/cmd/issue/list/list.go @@ -4,6 +4,7 @@ import ( "fmt" "net/http" "strconv" + "strings" "github.com/MakeNowJust/heredoc" "github.com/cli/cli/api" @@ -96,7 +97,7 @@ func listRun(opts *ListOptions) error { filterOptions := prShared.FilterOptions{ Entity: "issue", - State: opts.State, + State: strings.ToLower(opts.State), Assignee: opts.Assignee, Labels: opts.Labels, Author: opts.Author, @@ -132,8 +133,7 @@ func listRun(opts *ListOptions) error { defer opts.IO.StopPager() if isTerminal { - hasFilters := opts.State != "open" || len(opts.Labels) > 0 || opts.Assignee != "" || opts.Author != "" || opts.Mention != "" || opts.Milestone != "" || opts.Search != "" - title := prShared.ListHeader(ghrepo.FullName(baseRepo), "issue", len(listResult.Issues), listResult.TotalCount, hasFilters) + title := prShared.ListHeader(ghrepo.FullName(baseRepo), "issue", len(listResult.Issues), listResult.TotalCount, !filterOptions.IsDefault()) fmt.Fprintf(opts.IO.Out, "\n%s\n\n", title) } diff --git a/pkg/cmd/pr/list/list.go b/pkg/cmd/pr/list/list.go index bb4e5e0fe..97c35cd9c 100644 --- a/pkg/cmd/pr/list/list.go +++ b/pkg/cmd/pr/list/list.go @@ -120,8 +120,7 @@ func listRun(opts *ListOptions) error { defer opts.IO.StopPager() if opts.IO.IsStdoutTTY() { - hasFilters := opts.State != "open" || len(opts.Labels) > 0 || opts.BaseBranch != "" || opts.Author != "" || opts.Assignee != "" || opts.Search != "" - title := shared.ListHeader(ghrepo.FullName(baseRepo), "pull request", len(listResult.PullRequests), listResult.TotalCount, hasFilters) + title := shared.ListHeader(ghrepo.FullName(baseRepo), "pull request", len(listResult.PullRequests), listResult.TotalCount, !filters.IsDefault()) fmt.Fprintf(opts.IO.Out, "\n%s\n\n", title) } diff --git a/pkg/cmd/pr/shared/params.go b/pkg/cmd/pr/shared/params.go index 92bc8bf29..086d995a9 100644 --- a/pkg/cmd/pr/shared/params.go +++ b/pkg/cmd/pr/shared/params.go @@ -153,6 +153,34 @@ type FilterOptions struct { Search string } +func (opts *FilterOptions) IsDefault() bool { + if opts.State != "open" { + return false + } + if len(opts.Labels) > 0 { + return false + } + if opts.Assignee != "" { + return false + } + if opts.Author != "" { + return false + } + if opts.BaseBranch != "" { + return false + } + if opts.Mention != "" { + return false + } + if opts.Milestone != "" { + return false + } + if opts.Search != "" { + return false + } + return true +} + func ListURLWithQuery(listURL string, options FilterOptions) (string, error) { u, err := url.Parse(listURL) if err != nil {