| 13 | var pullRequestSearchQualifierRE = regexp.MustCompile(`(?i)\b(?:is|type):(?:pr|pull-?request)\b`) |
| 14 | |
| 15 | func listIssues(client *api.Client, repo ghrepo.Interface, filters prShared.FilterOptions, limit int) (*api.IssuesAndTotalCount, error) { |
| 16 | var states []string |
| 17 | switch filters.State { |
| 18 | case "open", "": |
| 19 | states = []string{"OPEN"} |
| 20 | case "closed": |
| 21 | states = []string{"CLOSED"} |
| 22 | case "all": |
| 23 | states = []string{"OPEN", "CLOSED"} |
| 24 | default: |
| 25 | return nil, fmt.Errorf("invalid state: %s", filters.State) |
| 26 | } |
| 27 | |
| 28 | fragments := fmt.Sprintf("fragment issue on Issue {%s}", api.IssueGraphQL(filters.Fields)) |
| 29 | query := fragments + ` |
| 30 | query IssueList($owner: String!, $repo: String!, $limit: Int, $endCursor: String, $states: [IssueState!] = OPEN, $assignee: String, $author: String, $mention: String) { |
| 31 | repository(owner: $owner, name: $repo) { |
| 32 | hasIssuesEnabled |
| 33 | issues(first: $limit, after: $endCursor, orderBy: {field: CREATED_AT, direction: DESC}, states: $states, filterBy: {assignee: $assignee, createdBy: $author, mentioned: $mention}) { |
| 34 | totalCount |
| 35 | nodes { |
| 36 | ...issue |
| 37 | } |
| 38 | pageInfo { |
| 39 | hasNextPage |
| 40 | endCursor |
| 41 | } |
| 42 | } |
| 43 | } |
| 44 | } |
| 45 | ` |
| 46 | |
| 47 | variables := map[string]interface{}{ |
| 48 | "owner": repo.RepoOwner(), |
| 49 | "repo": repo.RepoName(), |
| 50 | "states": states, |
| 51 | } |
| 52 | if filters.Assignee != "" { |
| 53 | variables["assignee"] = filters.Assignee |
| 54 | } |
| 55 | if filters.Author != "" { |
| 56 | variables["author"] = filters.Author |
| 57 | } |
| 58 | if filters.Mention != "" { |
| 59 | variables["mention"] = filters.Mention |
| 60 | } |
| 61 | |
| 62 | if filters.Milestone != "" { |
| 63 | // The "milestone" filter in the GraphQL connection doesn't work as documented and accepts neither a |
| 64 | // milestone number nor a title. It does accept a numeric database ID, but we cannot obtain one |
| 65 | // using the GraphQL API. |
| 66 | return nil, fmt.Errorf("cannot filter by milestone using the `Repository.issues` GraphQL connection") |
| 67 | } |
| 68 | |
| 69 | type responseData struct { |
| 70 | Repository struct { |
| 71 | Issues struct { |
| 72 | TotalCount int |