Merge pull request #625 from eddumelendez/add_author_flag_issues

Add filter issues by author
This commit is contained in:
Mislav Marohnić 2020-03-12 19:06:17 +01:00 committed by GitHub
commit 8913f6466d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 17 additions and 6 deletions

View file

@ -171,7 +171,7 @@ func IssueStatus(client *Client, repo ghrepo.Interface, currentUsername string)
return &payload, nil
}
func IssueList(client *Client, repo ghrepo.Interface, state string, labels []string, assigneeString string, limit int) ([]Issue, error) {
func IssueList(client *Client, repo ghrepo.Interface, state string, labels []string, assigneeString string, limit int, authorString string) ([]Issue, error) {
var states []string
switch state {
case "open", "":
@ -185,10 +185,10 @@ func IssueList(client *Client, repo ghrepo.Interface, state string, labels []str
}
query := fragments + `
query($owner: String!, $repo: String!, $limit: Int, $endCursor: String, $states: [IssueState!] = OPEN, $labels: [String!], $assignee: String) {
query($owner: String!, $repo: String!, $limit: Int, $endCursor: String, $states: [IssueState!] = OPEN, $labels: [String!], $assignee: String, $author: String) {
repository(owner: $owner, name: $repo) {
hasIssuesEnabled
issues(first: $limit, after: $endCursor, orderBy: {field: CREATED_AT, direction: DESC}, states: $states, labels: $labels, filterBy: {assignee: $assignee}) {
issues(first: $limit, after: $endCursor, orderBy: {field: CREATED_AT, direction: DESC}, states: $states, labels: $labels, filterBy: {assignee: $assignee, createdBy: $author}) {
nodes {
...issue
}
@ -212,6 +212,9 @@ func IssueList(client *Client, repo ghrepo.Interface, state string, labels []str
if assigneeString != "" {
variables["assignee"] = assigneeString
}
if authorString != "" {
variables["author"] = authorString
}
var response struct {
Repository struct {

View file

@ -38,7 +38,7 @@ func TestIssueList(t *testing.T) {
} } }
`))
_, err := IssueList(client, ghrepo.FromFullName("OWNER/REPO"), "open", []string{}, "", 251)
_, err := IssueList(client, ghrepo.FromFullName("OWNER/REPO"), "open", []string{}, "", 251, "")
if err != nil {
t.Fatalf("unexpected error: %v", err)
}

View file

@ -37,6 +37,7 @@ func init() {
issueListCmd.Flags().StringSliceP("label", "l", nil, "Filter by label")
issueListCmd.Flags().StringP("state", "s", "", "Filter by state: {open|closed|all}")
issueListCmd.Flags().IntP("limit", "L", 30, "Maximum number of issues to fetch")
issueListCmd.Flags().StringP("author", "A", "", "Filter by author")
issueViewCmd.Flags().BoolP("preview", "p", false, "Display preview of issue content")
}
@ -109,9 +110,14 @@ func issueList(cmd *cobra.Command, args []string) error {
return err
}
author, err := cmd.Flags().GetString("author")
if err != nil {
return err
}
fmt.Fprintf(colorableErr(cmd), "\nIssues for %s\n\n", ghrepo.FullName(baseRepo))
issues, err := api.IssueList(apiClient, baseRepo, state, labels, assignee, limit)
issues, err := api.IssueList(apiClient, baseRepo, state, labels, assignee, limit, author)
if err != nil {
return err
}

View file

@ -136,7 +136,7 @@ func TestIssueList_withFlags(t *testing.T) {
} } }
`))
output, err := RunCommand(issueListCmd, "issue list -a probablyCher -l web,bug -s open")
output, err := RunCommand(issueListCmd, "issue list -a probablyCher -l web,bug -s open -A foo")
if err != nil {
t.Errorf("error running command `issue list`: %v", err)
}
@ -154,6 +154,7 @@ No issues match your search
Assignee string
Labels []string
States []string
Author string
}
}{}
json.Unmarshal(bodyBytes, &reqBody)
@ -161,6 +162,7 @@ No issues match your search
eq(t, reqBody.Variables.Assignee, "probablyCher")
eq(t, reqBody.Variables.Labels, []string{"web", "bug"})
eq(t, reqBody.Variables.States, []string{"OPEN"})
eq(t, reqBody.Variables.Author, "foo")
}
func TestIssueList_nullAssigneeLabels(t *testing.T) {