MCPcopy
hub / github.com/cli/cli / ChecksStatus

Method ChecksStatus

api/queries_pr.go:332–405  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

330}
331
332func (pr *PullRequest) ChecksStatus() PullRequestChecksStatus {
333 var summary PullRequestChecksStatus
334
335 if len(pr.StatusCheckRollup.Nodes) == 0 {
336 return summary
337 }
338
339 contexts := pr.StatusCheckRollup.Nodes[0].Commit.StatusCheckRollup.Contexts
340
341 // If this commit has counts by state then we can summarise check status from those
342 if len(contexts.CheckRunCountsByState) != 0 && len(contexts.StatusContextCountsByState) != 0 {
343 summary.Total = contexts.CheckRunCount + contexts.StatusContextCount
344 for _, countByState := range contexts.CheckRunCountsByState {
345 switch parseCheckStatusFromCheckRunState(countByState.State) {
346 case passing:
347 summary.Passing += countByState.Count
348 case failing:
349 summary.Failing += countByState.Count
350 default:
351 summary.Pending += countByState.Count
352 }
353 }
354
355 for _, countByState := range contexts.StatusContextCountsByState {
356 switch parseCheckStatusFromStatusState(countByState.State) {
357 case passing:
358 summary.Passing += countByState.Count
359 case failing:
360 summary.Failing += countByState.Count
361 default:
362 summary.Pending += countByState.Count
363 }
364 }
365
366 return summary
367 }
368
369 // If we don't have the counts by state, then we'll need to summarise by looking at the more detailed contexts
370 for _, c := range contexts.Nodes {
371 // Nodes are a discriminated union of CheckRun or StatusContext and we can match on
372 // the TypeName to narrow the type.
373 if c.TypeName == "CheckRun" {
374 // https://docs.github.com/en/graphql/reference/enums#checkstatusstate
375 // If the status is completed then we can check the conclusion field
376 if c.Status == "COMPLETED" {
377 switch parseCheckStatusFromCheckConclusionState(c.Conclusion) {
378 case passing:
379 summary.Passing++
380 case failing:
381 summary.Failing++
382 default:
383 summary.Pending++
384 }
385 // otherwise we're in some form of pending state:
386 // "COMPLETED", "IN_PROGRESS", "PENDING", "QUEUED", "REQUESTED", "WAITING" or otherwise unknown
387 } else {
388 summary.Pending++
389 }