MCPcopy
hub / github.com/cli/cli / preloadIssueComments

Function preloadIssueComments

pkg/cmd/issue/view/http.go:11–54  ·  view source on GitHub ↗
(client *http.Client, repo ghrepo.Interface, issue *api.Issue)

Source from the content-addressed store, hash-verified

9)
10
11func preloadIssueComments(client *http.Client, repo ghrepo.Interface, issue *api.Issue) error {
12 type response struct {
13 Node struct {
14 Issue struct {
15 Comments *api.Comments `graphql:"comments(first: 100, after: $endCursor)"`
16 } `graphql:"...on Issue"`
17 PullRequest struct {
18 Comments *api.Comments `graphql:"comments(first: 100, after: $endCursor)"`
19 } `graphql:"...on PullRequest"`
20 } `graphql:"node(id: $id)"`
21 }
22
23 if !issue.Comments.PageInfo.HasNextPage {
24 return nil
25 }
26
27 variables := map[string]interface{}{
28 "id": githubv4.ID(issue.ID),
29 "endCursor": githubv4.String(issue.Comments.PageInfo.EndCursor),
30 }
31
32 gql := api.NewClientFromHTTP(client)
33 for {
34 var query response
35 err := gql.Query(repo.RepoHost(), "CommentsForIssue", &query, variables)
36 if err != nil {
37 return err
38 }
39
40 comments := query.Node.Issue.Comments
41 if comments == nil {
42 comments = query.Node.PullRequest.Comments
43 }
44
45 issue.Comments.Nodes = append(issue.Comments.Nodes, comments.Nodes...)
46 if !comments.PageInfo.HasNextPage {
47 break
48 }
49 variables["endCursor"] = githubv4.String(comments.PageInfo.EndCursor)
50 }
51
52 issue.Comments.PageInfo.HasNextPage = false
53 return nil
54}
55
56func preloadClosedByPullRequestsReferences(client *http.Client, repo ghrepo.Interface, issue *api.Issue) error {
57 if !issue.ClosedByPullRequestsReferences.PageInfo.HasNextPage {

Callers 1

viewRunFunction · 0.85

Calls 5

NewClientFromHTTPFunction · 0.92
IDMethod · 0.65
QueryMethod · 0.65
RepoHostMethod · 0.65
StringMethod · 0.45

Tested by

no test coverage detected