Skip to content

Support filtering by author for issues #389

Description

@sayboras

Describe the feature or problem you’d like to solve

Currently, we have filter based on --assignee, however we also need to filter by --author so that some of release tooling can pick it up and add details (you know we need to credit contributor 🥇 )

Proposed solution

Add flag --author in both commands, short hand flag might be finalized as -a is for assignee right now.

Additional context

Activity

  1. billygriffin commented on Feb 12, 2020

    @billygriffin
    Contributor

    I like this idea, thanks! We'll chat to make sure we're aligned on it and about how the flag should work.

  2. sayboras commented on Feb 12, 2020

    @sayboras
    Author

    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:abc in UI.

  3. mwean commented on Feb 13, 2020

    @mwean

    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.

  4. webern commented on Feb 25, 2020

    @webern

    I 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=someone

    Here'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
  5. changed the title [-]Support filtering by author for PR and issue[/-] [+]Support filtering by author for issues[/+] on Mar 11, 2020
  6. billygriffin commented on Mar 11, 2020

    @billygriffin
    Contributor

    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!

  7. sayboras commented on Mar 11, 2020

    @sayboras
    Author

    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 💯 🎉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementa request to improve CLI

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions