Repository navigation
Support filtering by author for issues #389
Description
Activity
I like this idea, thanks! We'll chat to make sure we're aligned on it and about how the flag should work.
Reacted by Tam Mach and Takayuki MaedaReacted by Tam Mach and Himanshu NailwalReacted by Tam Mach- addedenhancementa request to improve CLIa request to improve CLI
on Feb 12, 2020 I like this idea, thanks! We'll chat to make sure we're aligned on it and about how the flag should work.
Cool, I still feel that there will be more use case similar like this coming, so it's better to have expression filtering syntax like
is:pr author:abcin UI.it's better to have expression filtering syntax like is:pr author:abc in UI.
I agree. I'd love to use a query like
review-requested:@me, for example.Reacted by Benjamin WuethrichI realize this isn't PR-worthy (it does not work if someone wanted to search for both author and assignee, for example). But if anyone just needs to search PR's by author, this will work: https://github.com/webern/github-cli/tree/v0.5.7-pr-author-search
This works:
gh pr list --state=all --author=someoneHere's a patch that starts at v0.5.7
From e21e0df9618e9c6c400f16cd91d367b0c94eac84 Mon Sep 17 00:00:00 2001 From: Matt Briggs <[email protected]> Date: Tue, 25 Feb 2020 14:26:04 -0800 Subject: [PATCH] author search --- api/queries_pr.go | 55 +++++++++++++++++++++++++++++++++++++++++++++++ command/pr.go | 8 +++++++ 2 files changed, 63 insertions(+) diff --git a/api/queries_pr.go b/api/queries_pr.go index 734245a..3854416 100644 --- a/api/queries_pr.go +++ b/api/queries_pr.go @@ -556,6 +556,61 @@ func PullRequestList(client *Client, vars map[string]interface{}, limit int) ([] } } + // If author was specified, use the `search` API rather than + // `Repository.pullRequests`, but this mode doesn't support multiple labels + if author, ok := vars["author"].(string); ok { + query = fragment + ` + query( + $q: String!, + $limit: Int!, + $endCursor: String, + ) { + search(query: $q, type: ISSUE, first: $limit, after: $endCursor) { + edges { + node { + ...pr + } + } + pageInfo { + hasNextPage + endCursor + } + } + }` + owner := vars["owner"].(string) + repo := vars["repo"].(string) + search := []string{ + fmt.Sprintf("repo:%s/%s", owner, repo), + fmt.Sprintf("author:%s", author), + "is:pr", + "sort:created-desc", + } + if states, ok := vars["state"].([]string); ok && len(states) == 1 { + switch states[0] { + case "OPEN": + search = append(search, "state:open") + case "CLOSED": + search = append(search, "state:closed") + case "MERGED": + search = append(search, "is:merged") + } + } + if labels, ok := vars["labels"].([]string); ok && len(labels) > 0 { + if len(labels) > 1 { + return nil, fmt.Errorf("multiple labels with --author are not supported") + } + search = append(search, fmt.Sprintf(`label:"%s"`, labels[0])) + } + if baseBranch, ok := vars["baseBranch"].(string); ok { + search = append(search, fmt.Sprintf(`base:"%s"`, baseBranch)) + } + variables["q"] = strings.Join(search, " ") + } else { + for name, val := range vars { + variables[name] = val + } + } + for { variables["limit"] = pageLimit var data response diff --git a/command/pr.go b/command/pr.go index 9d3e248..ad6d7ab 100644 --- a/command/pr.go +++ b/command/pr.go @@ -30,6 +30,7 @@ func init() { prListCmd.Flags().StringP("base", "B", "", "Filter by base branch") prListCmd.Flags().StringSliceP("label", "l", nil, "Filter by label") prListCmd.Flags().StringP("assignee", "a", "", "Filter by assignee") + prListCmd.Flags().StringP("author", "u", "", "Filter by author") prViewCmd.Flags().BoolP("preview", "p", false, "Display preview of pull request content") } @@ -158,6 +159,10 @@ func prList(cmd *cobra.Command, args []string) error { if err != nil { return err } + author, err := cmd.Flags().GetString("author") + if err != nil { + return err + } var graphqlState []string switch state { @@ -187,6 +192,9 @@ func prList(cmd *cobra.Command, args []string) error { if assignee != "" { params["assignee"] = assignee } + if author != "" { + params["author"] = author + } prs, err := api.PullRequestList(apiClient, params, limit) if err != nil { -- 2.22.0
- changed the title
[-]Support filtering by author for PR and issue[/-][+]Support filtering by author for issues[/+]on Mar 11, 2020 We're currently blocked on the GraphQL API for adding filtering by author for PRs, but #625 adds it for issues. I renamed this issue to just issues, and I'll open up a new one for PRs, or we may consider a larger tracking issue for many of these similar filters. Thanks!
We're currently blocked on the GraphQL API for adding filtering by author for PRs, but #625 adds it for issues. I renamed this issue to just issues, and I'll open up a new one for PRs, or we may consider a larger tracking issue for many of these similar filters. Thanks!
Sounds good 💯 🎉
Describe the feature or problem you’d like to solve
Currently, we have filter based on
--assignee, however we also need to filter by--authorso that some of release tooling can pick it up and add details (you know we need to credit contributor 🥇 )Proposed solution
Add flag
--authorin both commands, short hand flag might be finalized as-ais for assignee right now.Additional context