X Tutup
Skip to content

Commit 2fa8a85

Browse files
committed
Unify checking whether search filters were passed by the user
1 parent f008c61 commit 2fa8a85

File tree

3 files changed

+32
-5
lines changed

3 files changed

+32
-5
lines changed

pkg/cmd/issue/list/list.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"fmt"
55
"net/http"
66
"strconv"
7+
"strings"
78

89
"github.com/MakeNowJust/heredoc"
910
"github.com/cli/cli/api"
@@ -96,7 +97,7 @@ func listRun(opts *ListOptions) error {
9697

9798
filterOptions := prShared.FilterOptions{
9899
Entity: "issue",
99-
State: opts.State,
100+
State: strings.ToLower(opts.State),
100101
Assignee: opts.Assignee,
101102
Labels: opts.Labels,
102103
Author: opts.Author,
@@ -132,8 +133,7 @@ func listRun(opts *ListOptions) error {
132133
defer opts.IO.StopPager()
133134

134135
if isTerminal {
135-
hasFilters := opts.State != "open" || len(opts.Labels) > 0 || opts.Assignee != "" || opts.Author != "" || opts.Mention != "" || opts.Milestone != "" || opts.Search != ""
136-
title := prShared.ListHeader(ghrepo.FullName(baseRepo), "issue", len(listResult.Issues), listResult.TotalCount, hasFilters)
136+
title := prShared.ListHeader(ghrepo.FullName(baseRepo), "issue", len(listResult.Issues), listResult.TotalCount, !filterOptions.IsDefault())
137137
fmt.Fprintf(opts.IO.Out, "\n%s\n\n", title)
138138
}
139139

pkg/cmd/pr/list/list.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,8 +120,7 @@ func listRun(opts *ListOptions) error {
120120
defer opts.IO.StopPager()
121121

122122
if opts.IO.IsStdoutTTY() {
123-
hasFilters := opts.State != "open" || len(opts.Labels) > 0 || opts.BaseBranch != "" || opts.Author != "" || opts.Assignee != "" || opts.Search != ""
124-
title := shared.ListHeader(ghrepo.FullName(baseRepo), "pull request", len(listResult.PullRequests), listResult.TotalCount, hasFilters)
123+
title := shared.ListHeader(ghrepo.FullName(baseRepo), "pull request", len(listResult.PullRequests), listResult.TotalCount, !filters.IsDefault())
125124
fmt.Fprintf(opts.IO.Out, "\n%s\n\n", title)
126125
}
127126

pkg/cmd/pr/shared/params.go

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,34 @@ type FilterOptions struct {
153153
Search string
154154
}
155155

156+
func (opts *FilterOptions) IsDefault() bool {
157+
if opts.State != "open" {
158+
return false
159+
}
160+
if len(opts.Labels) > 0 {
161+
return false
162+
}
163+
if opts.Assignee != "" {
164+
return false
165+
}
166+
if opts.Author != "" {
167+
return false
168+
}
169+
if opts.BaseBranch != "" {
170+
return false
171+
}
172+
if opts.Mention != "" {
173+
return false
174+
}
175+
if opts.Milestone != "" {
176+
return false
177+
}
178+
if opts.Search != "" {
179+
return false
180+
}
181+
return true
182+
}
183+
156184
func ListURLWithQuery(listURL string, options FilterOptions) (string, error) {
157185
u, err := url.Parse(listURL)
158186
if err != nil {

0 commit comments

Comments
 (0)
X Tutup