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

Function populateStatusChecks

pkg/cmd/pr/checks/checks.go:256–310  ·  view source on GitHub ↗
(client *http.Client, repo ghrepo.Interface, pr *api.PullRequest, requiredChecks bool, includeEvent bool)

Source from the content-addressed store, hash-verified

254}
255
256func populateStatusChecks(client *http.Client, repo ghrepo.Interface, pr *api.PullRequest, requiredChecks bool, includeEvent bool) ([]check, checkCounts, error) {
257 apiClient := api.NewClientFromHTTP(client)
258
259 type response struct {
260 Node *api.PullRequest
261 }
262
263 query := fmt.Sprintf(`
264 query PullRequestStatusChecks($id: ID!, $endCursor: String) {
265 node(id: $id) {
266 ...on PullRequest {
267 %s
268 }
269 }
270 }`, api.RequiredStatusCheckRollupGraphQL("$id", "$endCursor", includeEvent))
271
272 variables := map[string]any{
273 "id": pr.ID,
274 }
275
276 statusCheckRollup := api.CheckContexts{}
277
278 for {
279 var resp response
280 err := apiClient.GraphQL(repo.RepoHost(), query, variables, &resp)
281 if err != nil {
282 return nil, checkCounts{}, err
283 }
284
285 if len(resp.Node.StatusCheckRollup.Nodes) == 0 {
286 return nil, checkCounts{}, errors.New("no commit found on the pull request")
287 }
288
289 result := resp.Node.StatusCheckRollup.Nodes[0].Commit.StatusCheckRollup.Contexts
290 statusCheckRollup.Nodes = append(
291 statusCheckRollup.Nodes,
292 result.Nodes...,
293 )
294
295 if !result.PageInfo.HasNextPage {
296 break
297 }
298 variables["endCursor"] = result.PageInfo.EndCursor
299 }
300
301 if len(statusCheckRollup.Nodes) == 0 {
302 return nil, checkCounts{}, fmt.Errorf("no checks reported on the '%s' branch", pr.HeadRefName)
303 }
304
305 checks, counts := aggregateChecks(statusCheckRollup.Nodes, requiredChecks)
306 if len(checks) == 0 && requiredChecks {
307 return checks, counts, fmt.Errorf("no required checks reported on the '%s' branch", pr.HeadRefName)
308 }
309 return checks, counts, nil
310}

Callers 1

checksRunFunction · 0.85

Calls 6

NewClientFromHTTPFunction · 0.92
aggregateChecksFunction · 0.85
GraphQLMethod · 0.80
RepoHostMethod · 0.65
ErrorfMethod · 0.65

Tested by

no test coverage detected