X Tutup
Skip to content

Commit 9aebb66

Browse files
committed
Add milestone filter
1 parent 2943703 commit 9aebb66

File tree

4 files changed

+16
-5
lines changed

4 files changed

+16
-5
lines changed

api/queries_issue.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ func IssueStatus(client *Client, repo ghrepo.Interface, currentUsername string)
198198
return &payload, nil
199199
}
200200

201-
func IssueList(client *Client, repo ghrepo.Interface, state string, labels []string, assigneeString string, limit int, authorString string, mentionedString string) (*IssuesAndTotalCount, error) {
201+
func IssueList(client *Client, repo ghrepo.Interface, state string, labels []string, assigneeString string, limit int, authorString string, mentionedString string, milestoneString string) (*IssuesAndTotalCount, error) {
202202
var states []string
203203
switch state {
204204
case "open", "":
@@ -215,7 +215,7 @@ func IssueList(client *Client, repo ghrepo.Interface, state string, labels []str
215215
query($owner: String!, $repo: String!, $limit: Int, $endCursor: String, $states: [IssueState!] = OPEN, $labels: [String!], $assignee: String, $author: String) {
216216
repository(owner: $owner, name: $repo) {
217217
hasIssuesEnabled
218-
issues(first: $limit, after: $endCursor, orderBy: {field: CREATED_AT, direction: DESC}, states: $states, labels: $labels, filterBy: {assignee: $assignee, createdBy: $author, mentioned: $mentioned}) {
218+
issues(first: $limit, after: $endCursor, orderBy: {field: CREATED_AT, direction: DESC}, states: $states, labels: $labels, filterBy: {assignee: $assignee, createdBy: $author, mentioned: $mentioned, milestone: $milestone}) {
219219
totalCount
220220
nodes {
221221
...issue
@@ -246,6 +246,9 @@ func IssueList(client *Client, repo ghrepo.Interface, state string, labels []str
246246
if mentionedString != "" {
247247
variables["mentioned"] = mentionedString
248248
}
249+
if milestoneString != "" {
250+
variables["milestone"] = milestoneString
251+
}
249252

250253
var response struct {
251254
Repository struct {

api/queries_issue_test.go

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

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

command/issue.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ func init() {
4242
issueListCmd.Flags().IntP("limit", "L", 30, "Maximum number of issues to fetch")
4343
issueListCmd.Flags().StringP("author", "A", "", "Filter by author")
4444
issueListCmd.Flags().StringP("mentioned", "", "", "Filter by mention")
45+
issueListCmd.Flags().StringP("milestone", "", "", "Filter by milestone")
4546

4647
issueCmd.AddCommand(issueViewCmd)
4748
issueViewCmd.Flags().BoolP("web", "w", false, "Open an issue in the browser")
@@ -147,7 +148,12 @@ func issueList(cmd *cobra.Command, args []string) error {
147148
return err
148149
}
149150

150-
listResult, err := api.IssueList(apiClient, baseRepo, state, labels, assignee, limit, author, mentioned)
151+
milestone, err := cmd.Flags().GetString("milestone")
152+
if err != nil {
153+
return err
154+
}
155+
156+
listResult, err := api.IssueList(apiClient, baseRepo, state, labels, assignee, limit, author, mentioned, milestone)
151157
if err != nil {
152158
return err
153159
}

command/issue_test.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ func TestIssueList_withFlags(t *testing.T) {
153153
} } }
154154
`))
155155

156-
output, err := RunCommand("issue list -a probablyCher -l web,bug -s open -A foo --mentioned me")
156+
output, err := RunCommand("issue list -a probablyCher -l web,bug -s open -A foo --mentioned me --milestone 1.x")
157157
if err != nil {
158158
t.Errorf("error running command `issue list`: %v", err)
159159
}
@@ -172,6 +172,7 @@ No issues match your search in OWNER/REPO
172172
States []string
173173
Author string
174174
Mentioned string
175+
Milestone string
175176
}
176177
}{}
177178
_ = json.Unmarshal(bodyBytes, &reqBody)
@@ -181,6 +182,7 @@ No issues match your search in OWNER/REPO
181182
eq(t, reqBody.Variables.States, []string{"OPEN"})
182183
eq(t, reqBody.Variables.Author, "foo")
183184
eq(t, reqBody.Variables.Mentioned, "me")
185+
eq(t, reqBody.Variables.Milestone, "1.x")
184186
}
185187

186188
func TestIssueList_withInvalidLimitFlag(t *testing.T) {

0 commit comments

Comments
 (0)
X Tutup