From 01bbb15b57118befe4416d4785ffdd87a45a8f33 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mislav=20Marohni=C4=87?= Date: Tue, 23 Mar 2021 21:48:51 +0100 Subject: [PATCH] Add `pr list --search` --- pkg/cmd/issue/list/list.go | 3 ++- pkg/cmd/pr/list/http.go | 3 ++- pkg/cmd/pr/list/list.go | 8 +++++--- 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/pkg/cmd/issue/list/list.go b/pkg/cmd/issue/list/list.go index 84e5f1d52..88fe2fecf 100644 --- a/pkg/cmd/issue/list/list.go +++ b/pkg/cmd/issue/list/list.go @@ -78,7 +78,8 @@ func NewCmdList(f *cmdutil.Factory, runF func(*ListOptions) error) *cobra.Comman cmd.Flags().StringVarP(&opts.Author, "author", "A", "", "Filter by author") cmd.Flags().StringVar(&opts.Mention, "mention", "", "Filter by mention") cmd.Flags().StringVarP(&opts.Milestone, "milestone", "m", "", "Filter by milestone `number` or `title`") - cmd.Flags().StringVarP(&opts.Search, "search", "S", "", "Search issues with filter") + cmd.Flags().StringVarP(&opts.Search, "search", "S", "", "Search issues with `query`") + return cmd } diff --git a/pkg/cmd/pr/list/http.go b/pkg/cmd/pr/list/http.go index 3a164800f..2511493a2 100644 --- a/pkg/cmd/pr/list/http.go +++ b/pkg/cmd/pr/list/http.go @@ -24,7 +24,7 @@ const fragment = `fragment pr on PullRequest { }` func listPullRequests(httpClient *http.Client, repo ghrepo.Interface, filters prShared.FilterOptions, limit int) (*api.PullRequestAndTotalCount, error) { - if filters.Assignee != "" { + if filters.Assignee != "" || filters.Search != "" { return searchPullRequests(httpClient, repo, filters, limit) } @@ -171,6 +171,7 @@ func searchPullRequests(httpClient *http.Client, repo ghrepo.Interface, filters q := githubsearch.NewQuery() q.SetType(githubsearch.PullRequest) q.InRepository(ghrepo.FullName(repo)) + q.AddQuery(filters.Search) q.SortBy(githubsearch.CreatedAt, githubsearch.Desc) switch filters.State { diff --git a/pkg/cmd/pr/list/list.go b/pkg/cmd/pr/list/list.go index 25f577c00..79ac37ace 100644 --- a/pkg/cmd/pr/list/list.go +++ b/pkg/cmd/pr/list/list.go @@ -28,6 +28,7 @@ type ListOptions struct { BaseBranch string Labels []string Assignee string + Search string } func NewCmdList(f *cmdutil.Factory, runF func(*ListOptions) error) *cobra.Command { @@ -40,9 +41,8 @@ func NewCmdList(f *cmdutil.Factory, runF func(*ListOptions) error) *cobra.Comman Use: "list", Short: "List and filter pull requests in this repository", Example: heredoc.Doc(` - $ gh pr list --limit 999 - $ gh pr list --state closed - $ gh pr list --label "priority 1" --label "bug" + $ gh pr list --label bug --label "priority 1" + $ gh pr list --search "status:success review:required" $ gh pr list --web `), Args: cmdutil.NoArgsQuoteReminder, @@ -67,6 +67,7 @@ func NewCmdList(f *cmdutil.Factory, runF func(*ListOptions) error) *cobra.Comman cmd.Flags().StringVarP(&opts.BaseBranch, "base", "B", "", "Filter by base branch") cmd.Flags().StringSliceVarP(&opts.Labels, "label", "l", nil, "Filter by labels") cmd.Flags().StringVarP(&opts.Assignee, "assignee", "a", "", "Filter by assignee") + cmd.Flags().StringVarP(&opts.Search, "search", "S", "", "Search pull requests with `query`") return cmd } @@ -88,6 +89,7 @@ func listRun(opts *ListOptions) error { Assignee: opts.Assignee, Labels: opts.Labels, BaseBranch: opts.BaseBranch, + Search: opts.Search, } if opts.WebMode {