MCPcopy Index your code
hub / github.com/cli/cli / listIssues

Function listIssues

pkg/cmd/issue/list/http.go:15–117  ·  view source on GitHub ↗
(client *api.Client, repo ghrepo.Interface, filters prShared.FilterOptions, limit int)

Source from the content-addressed store, hash-verified

13var pullRequestSearchQualifierRE = regexp.MustCompile(`(?i)\b(?:is|type):(?:pr|pull-?request)\b`)
14
15func 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

Callers 3

issueListFunction · 0.85
TestIssueListFunction · 0.85
TestIssueList_paginationFunction · 0.85

Calls 8

IssueGraphQLFunction · 0.92
FullNameFunction · 0.92
GraphQLMethod · 0.80
minFunction · 0.70
ErrorfMethod · 0.65
RepoOwnerMethod · 0.65
RepoNameMethod · 0.65
RepoHostMethod · 0.65

Tested by 2

TestIssueListFunction · 0.68
TestIssueList_paginationFunction · 0.68