Skip to content

Commit 8e7ba90

Browse files
committed
Add filter issues by author
1 parent 115b4b5 commit 8e7ba90

File tree

5 files changed

+29
-6
lines changed

5 files changed

+29
-6
lines changed

api/queries_issue.go

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,9 @@ const fragments = `
5555
}
5656
totalCount
5757
}
58+
author {
59+
login
60+
}
5861
}
5962
`
6063

@@ -171,7 +174,7 @@ func IssueStatus(client *Client, repo ghrepo.Interface, currentUsername string)
171174
return &payload, nil
172175
}
173176

174-
func IssueList(client *Client, repo ghrepo.Interface, state string, labels []string, assigneeString string, limit int) ([]Issue, error) {
177+
func IssueList(client *Client, repo ghrepo.Interface, state string, labels []string, assigneeString string, limit int, authorString string) ([]Issue, error) {
175178
var states []string
176179
switch state {
177180
case "open", "":
@@ -185,10 +188,10 @@ func IssueList(client *Client, repo ghrepo.Interface, state string, labels []str
185188
}
186189

187190
query := fragments + `
188-
query($owner: String!, $repo: String!, $limit: Int, $endCursor: String, $states: [IssueState!] = OPEN, $labels: [String!], $assignee: String) {
191+
query($owner: String!, $repo: String!, $limit: Int, $endCursor: String, $states: [IssueState!] = OPEN, $labels: [String!], $assignee: String, $author: String) {
189192
repository(owner: $owner, name: $repo) {
190193
hasIssuesEnabled
191-
issues(first: $limit, after: $endCursor, orderBy: {field: CREATED_AT, direction: DESC}, states: $states, labels: $labels, filterBy: {assignee: $assignee}) {
194+
issues(first: $limit, after: $endCursor, orderBy: {field: CREATED_AT, direction: DESC}, states: $states, labels: $labels, filterBy: {assignee: $assignee, createdBy: $author}) {
192195
nodes {
193196
...issue
194197
}
@@ -212,6 +215,9 @@ func IssueList(client *Client, repo ghrepo.Interface, state string, labels []str
212215
if assigneeString != "" {
213216
variables["assignee"] = assigneeString
214217
}
218+
if authorString != "" {
219+
variables["author"] = authorString
220+
}
215221

216222
var response struct {
217223
Repository struct {

api/queries_issue_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ func TestIssueList(t *testing.T) {
3838
} } }
3939
`))
4040

41-
_, err := IssueList(client, ghrepo.FromFullName("OWNER/REPO"), "open", []string{}, "", 251)
41+
_, err := IssueList(client, ghrepo.FromFullName("OWNER/REPO"), "open", []string{}, "", 251, "")
4242
if err != nil {
4343
t.Fatalf("unexpected error: %v", err)
4444
}

command/issue.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ func init() {
3737
issueListCmd.Flags().StringSliceP("label", "l", nil, "Filter by label")
3838
issueListCmd.Flags().StringP("state", "s", "", "Filter by state: {open|closed|all}")
3939
issueListCmd.Flags().IntP("limit", "L", 30, "Maximum number of issues to fetch")
40+
issueListCmd.Flags().StringP("author", "A", "", "Filter by author")
4041

4142
issueViewCmd.Flags().BoolP("preview", "p", false, "Display preview of issue content")
4243
}
@@ -109,9 +110,14 @@ func issueList(cmd *cobra.Command, args []string) error {
109110
return err
110111
}
111112

113+
author, err := cmd.Flags().GetString("author")
114+
if err != nil {
115+
return err
116+
}
117+
112118
fmt.Fprintf(colorableErr(cmd), "\nIssues for %s\n\n", ghrepo.FullName(baseRepo))
113119

114-
issues, err := api.IssueList(apiClient, baseRepo, state, labels, assignee, limit)
120+
issues, err := api.IssueList(apiClient, baseRepo, state, labels, assignee, limit, author)
115121
if err != nil {
116122
return err
117123
}

command/issue_test.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ func TestIssueList_withFlags(t *testing.T) {
136136
} } }
137137
`))
138138

139-
output, err := RunCommand(issueListCmd, "issue list -a probablyCher -l web,bug -s open")
139+
output, err := RunCommand(issueListCmd, "issue list -a probablyCher -l web,bug -s open -A foo")
140140
if err != nil {
141141
t.Errorf("error running command `issue list`: %v", err)
142142
}
@@ -154,13 +154,15 @@ No issues match your search
154154
Assignee string
155155
Labels []string
156156
States []string
157+
Author string
157158
}
158159
}{}
159160
json.Unmarshal(bodyBytes, &reqBody)
160161

161162
eq(t, reqBody.Variables.Assignee, "probablyCher")
162163
eq(t, reqBody.Variables.Labels, []string{"web", "bug"})
163164
eq(t, reqBody.Variables.States, []string{"OPEN"})
165+
eq(t, reqBody.Variables.Author, "foo")
164166
}
165167

166168
func TestIssueList_nullAssigneeLabels(t *testing.T) {

test/fixtures/issueList.json

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@
1515
}
1616
],
1717
"totalCount": 1
18+
},
19+
"author": {
20+
"login": "foo"
1821
}
1922
},
2023
{
@@ -28,6 +31,9 @@
2831
}
2932
],
3033
"totalCount": 1
34+
},
35+
"author": {
36+
"login": "bar"
3137
}
3238
},
3339
{
@@ -41,6 +47,9 @@
4147
}
4248
],
4349
"totalCount": 1
50+
},
51+
"author": {
52+
"login": "bar"
4453
}
4554
}
4655
]

0 commit comments

Comments
 (0)