MCPcopy Create free account
hub / github.com/cli/cli / preloadPrComments

Function preloadPrComments

pkg/cmd/pr/shared/finder.go:482–520  ·  view source on GitHub ↗
(client *http.Client, repo ghrepo.Interface, pr *api.PullRequest)

Source from the content-addressed store, hash-verified

480}
481
482func preloadPrComments(client *http.Client, repo ghrepo.Interface, pr *api.PullRequest) error {
483 if !pr.Comments.PageInfo.HasNextPage {
484 return nil
485 }
486
487 type response struct {
488 Node struct {
489 PullRequest struct {
490 Comments api.Comments `graphql:"comments(first: 100, after: $endCursor)"`
491 } `graphql:"...on PullRequest"`
492 } `graphql:"node(id: $id)"`
493 }
494
495 variables := map[string]any{
496 "id": githubv4.ID(pr.ID),
497 "endCursor": githubv4.String(pr.Comments.PageInfo.EndCursor),
498 }
499
500 gql := api.NewClientFromHTTP(client)
501
502 for {
503 var query response
504 err := gql.Query(repo.RepoHost(), "CommentsForPullRequest", &query, variables)
505 if err != nil {
506 return err
507 }
508
509 pr.Comments.Nodes = append(pr.Comments.Nodes, query.Node.PullRequest.Comments.Nodes...)
510 pr.Comments.TotalCount = len(pr.Comments.Nodes)
511
512 if !query.Node.PullRequest.Comments.PageInfo.HasNextPage {
513 break
514 }
515 variables["endCursor"] = githubv4.String(query.Node.PullRequest.Comments.PageInfo.EndCursor)
516 }
517
518 pr.Comments.PageInfo.HasNextPage = false
519 return nil
520}
521
522func preloadPrClosingIssuesReferences(client *http.Client, repo ghrepo.Interface, pr *api.PullRequest) error {
523 if !pr.ClosingIssuesReferences.PageInfo.HasNextPage {

Callers 1

FindMethod · 0.85

Calls 5

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

Tested by

no test coverage detected