Add mentioned flag

This commit is contained in:
Eddú Meléndez 2020-03-12 21:40:11 -06:00
parent 54e0534b1b
commit 2943703d4a
4 changed files with 20 additions and 9 deletions

View file

@ -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, mentionedString string) (*IssuesAndTotalCount, error) {
var states []string
switch state {
case "open", "":
@ -215,7 +215,7 @@ func IssueList(client *Client, repo ghrepo.Interface, state string, labels []str
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, createdBy: $author}) {
issues(first: $limit, after: $endCursor, orderBy: {field: CREATED_AT, direction: DESC}, states: $states, labels: $labels, filterBy: {assignee: $assignee, createdBy: $author, mentioned: $mentioned}) {
totalCount
nodes {
...issue
@ -243,6 +243,9 @@ func IssueList(client *Client, repo ghrepo.Interface, state string, labels []str
if authorString != "" {
variables["author"] = authorString
}
if mentionedString != "" {
variables["mentioned"] = mentionedString
}
var response struct {
Repository struct {

View file

@ -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)
}

View file

@ -41,6 +41,7 @@ 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().StringP("mentioned", "", "", "Filter by mention")
issueCmd.AddCommand(issueViewCmd)
issueViewCmd.Flags().BoolP("web", "w", false, "Open an issue in the browser")
@ -141,7 +142,12 @@ func issueList(cmd *cobra.Command, args []string) error {
return err
}
listResult, err := api.IssueList(apiClient, baseRepo, state, labels, assignee, limit, author)
mentioned, err := cmd.Flags().GetString("mentioned")
if err != nil {
return err
}
listResult, err := api.IssueList(apiClient, baseRepo, state, labels, assignee, limit, author, mentioned)
if err != nil {
return err
}

View file

@ -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 --mentioned me")
if err != nil {
t.Errorf("error running command `issue list`: %v", err)
}
@ -167,10 +167,11 @@ 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
Mentioned string
}
}{}
_ = json.Unmarshal(bodyBytes, &reqBody)
@ -179,6 +180,7 @@ 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.Mentioned, "me")
}
func TestIssueList_withInvalidLimitFlag(t *testing.T) {