X Tutup
Skip to content

Commit 2943703

Browse files
committed
Add mentioned flag
1 parent 54e0534 commit 2943703

File tree

4 files changed

+20
-9
lines changed

4 files changed

+20
-9
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) (*IssuesAndTotalCount, error) {
201+
func IssueList(client *Client, repo ghrepo.Interface, state string, labels []string, assigneeString string, limit int, authorString string, mentionedString 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}) {
218+
issues(first: $limit, after: $endCursor, orderBy: {field: CREATED_AT, direction: DESC}, states: $states, labels: $labels, filterBy: {assignee: $assignee, createdBy: $author, mentioned: $mentioned}) {
219219
totalCount
220220
nodes {
221221
...issue
@@ -243,6 +243,9 @@ func IssueList(client *Client, repo ghrepo.Interface, state string, labels []str
243243
if authorString != "" {
244244
variables["author"] = authorString
245245
}
246+
if mentionedString != "" {
247+
variables["mentioned"] = mentionedString
248+
}
246249

247250
var response struct {
248251
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
@@ -41,6 +41,7 @@ func init() {
4141
issueListCmd.Flags().StringP("state", "s", "open", "Filter by state: {open|closed|all}")
4242
issueListCmd.Flags().IntP("limit", "L", 30, "Maximum number of issues to fetch")
4343
issueListCmd.Flags().StringP("author", "A", "", "Filter by author")
44+
issueListCmd.Flags().StringP("mentioned", "", "", "Filter by mention")
4445

4546
issueCmd.AddCommand(issueViewCmd)
4647
issueViewCmd.Flags().BoolP("web", "w", false, "Open an issue in the browser")
@@ -141,7 +142,12 @@ func issueList(cmd *cobra.Command, args []string) error {
141142
return err
142143
}
143144

144-
listResult, err := api.IssueList(apiClient, baseRepo, state, labels, assignee, limit, author)
145+
mentioned, err := cmd.Flags().GetString("mentioned")
146+
if err != nil {
147+
return err
148+
}
149+
150+
listResult, err := api.IssueList(apiClient, baseRepo, state, labels, assignee, limit, author, mentioned)
145151
if err != nil {
146152
return err
147153
}

command/issue_test.go

Lines changed: 7 additions & 5 deletions
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")
156+
output, err := RunCommand("issue list -a probablyCher -l web,bug -s open -A foo --mentioned me")
157157
if err != nil {
158158
t.Errorf("error running command `issue list`: %v", err)
159159
}
@@ -167,10 +167,11 @@ No issues match your search in OWNER/REPO
167167
bodyBytes, _ := ioutil.ReadAll(http.Requests[1].Body)
168168
reqBody := struct {
169169
Variables struct {
170-
Assignee string
171-
Labels []string
172-
States []string
173-
Author string
170+
Assignee string
171+
Labels []string
172+
States []string
173+
Author string
174+
Mentioned string
174175
}
175176
}{}
176177
_ = json.Unmarshal(bodyBytes, &reqBody)
@@ -179,6 +180,7 @@ No issues match your search in OWNER/REPO
179180
eq(t, reqBody.Variables.Labels, []string{"web", "bug"})
180181
eq(t, reqBody.Variables.States, []string{"OPEN"})
181182
eq(t, reqBody.Variables.Author, "foo")
183+
eq(t, reqBody.Variables.Mentioned, "me")
182184
}
183185

184186
func TestIssueList_withInvalidLimitFlag(t *testing.T) {

0 commit comments

Comments
 (0)
X Tutup