Unify checking whether search filters were passed by the user

This commit is contained in:
Mislav Marohnić 2021-03-24 18:11:21 +01:00
parent f008c61d13
commit 2fa8a85813
3 changed files with 32 additions and 5 deletions

View file

@ -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)
}

View file

@ -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)
}

View file

@ -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 {