Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions api/queries_issue.go
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,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, authorString string) (*IssuesAndTotalCount, error) {
func IssueList(client *Client, repo ghrepo.Interface, state string, labels []string, assigneeString string, limit int, authorString string, mentionString string, milestoneString string) (*IssuesAndTotalCount, error) {
var states []string
switch state {
case "open", "":
Expand All @@ -212,10 +212,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, $author: String) {
query($owner: String!, $repo: String!, $limit: Int, $endCursor: String, $states: [IssueState!] = OPEN, $labels: [String!], $assignee: String, $author: String, $mention: String, $milestone: String) {
repository(owner: $owner, name: $repo) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hasIssuesEnabled
issues(first: $limit, after: $endCursor, orderBy: {field: CREATED_AT, direction: DESC}, states: $states, labels: $labels, filterBy: {assignee: $assignee, createdBy: $author}) {
issues(first: $limit, after: $endCursor, orderBy: {field: CREATED_AT, direction: DESC}, states: $states, labels: $labels, filterBy: {assignee: $assignee, createdBy: $author, mentioned: $mention, milestone: $milestone}) {
totalCount
nodes {
...issue
Expand Down Expand Up @@ -243,6 +243,12 @@ func IssueList(client *Client, repo ghrepo.Interface, state string, labels []str
if authorString != "" {
variables["author"] = authorString
}
if mentionString != "" {
variables["mention"] = mentionString
}
if milestoneString != "" {
variables["milestone"] = milestoneString
}

var response struct {
Repository struct {
Expand Down
2 changes: 1 addition & 1 deletion api/queries_issue_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func TestIssueList(t *testing.T) {
`))

repo, _ := ghrepo.FromFullName("OWNER/REPO")
_, err := IssueList(client, repo, "open", []string{}, "", 251, "")
_, err := IssueList(client, repo, "open", []string{}, "", 251, "", "", "")
if err != nil {
t.Fatalf("unexpected error: %v", err)
}
Expand Down
16 changes: 14 additions & 2 deletions command/issue.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ func init() {
issueListCmd.Flags().StringP("state", "s", "open", "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")
issueListCmd.Flags().String("mention", "", "Filter by mention")
issueListCmd.Flags().StringP("milestone", "m", "", "Filter by milestone `name`")

issueCmd.AddCommand(issueViewCmd)
issueViewCmd.Flags().BoolP("web", "w", false, "Open an issue in the browser")
Expand Down Expand Up @@ -156,15 +158,25 @@ func issueList(cmd *cobra.Command, args []string) error {
return err
}

listResult, err := api.IssueList(apiClient, baseRepo, state, labels, assignee, limit, author)
mention, err := cmd.Flags().GetString("mention")
if err != nil {
return err
}

milestone, err := cmd.Flags().GetString("milestone")
if err != nil {
return err
}

listResult, err := api.IssueList(apiClient, baseRepo, state, labels, assignee, limit, author, mention, milestone)
if err != nil {
return err
}

hasFilters := false
cmd.Flags().Visit(func(f *pflag.Flag) {
switch f.Name {
case "state", "label", "assignee", "author":
case "state", "label", "assignee", "author", "mention", "milestone":
hasFilters = true
}
})
Expand Down
14 changes: 9 additions & 5 deletions command/issue_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ func TestIssueList_withFlags(t *testing.T) {
} } }
`))

output, err := RunCommand("issue list -a probablyCher -l web,bug -s open -A foo")
output, err := RunCommand("issue list -a probablyCher -l web,bug -s open -A foo --mention me --milestone 1.x")
if err != nil {
t.Errorf("error running command `issue list`: %v", err)
}
Expand All @@ -167,10 +167,12 @@ No issues match your search in OWNER/REPO
bodyBytes, _ := ioutil.ReadAll(http.Requests[1].Body)
reqBody := struct {
Variables struct {
Assignee string
Labels []string
States []string
Author string
Assignee string
Labels []string
States []string
Author string
Mention string
Milestone string
}
}{}
_ = json.Unmarshal(bodyBytes, &reqBody)
Expand All @@ -179,6 +181,8 @@ No issues match your search in OWNER/REPO
eq(t, reqBody.Variables.Labels, []string{"web", "bug"})
eq(t, reqBody.Variables.States, []string{"OPEN"})
eq(t, reqBody.Variables.Author, "foo")
eq(t, reqBody.Variables.Mention, "me")
eq(t, reqBody.Variables.Milestone, "1.x")
}

func TestIssueList_withInvalidLimitFlag(t *testing.T) {
Expand Down