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

Method ChecksStatus

api/queries_pr.go:357–430  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

355}
356
357func (pr *PullRequest) ChecksStatus() PullRequestChecksStatus {
358 var summary PullRequestChecksStatus
359
360 if len(pr.StatusCheckRollup.Nodes) == 0 {
361 return summary
362 }
363
364 contexts := pr.StatusCheckRollup.Nodes[0].Commit.StatusCheckRollup.Contexts
365
366 // If this commit has counts by state then we can summarise check status from those
367 if len(contexts.CheckRunCountsByState) != 0 && len(contexts.StatusContextCountsByState) != 0 {
368 summary.Total = contexts.CheckRunCount + contexts.StatusContextCount
369 for _, countByState := range contexts.CheckRunCountsByState {
370 switch parseCheckStatusFromCheckRunState(countByState.State) {
371 case passing:
372 summary.Passing += countByState.Count
373 case failing:
374 summary.Failing += countByState.Count
375 default:
376 summary.Pending += countByState.Count
377 }
378 }
379
380 for _, countByState := range contexts.StatusContextCountsByState {
381 switch parseCheckStatusFromStatusState(countByState.State) {
382 case passing:
383 summary.Passing += countByState.Count
384 case failing:
385 summary.Failing += countByState.Count
386 default:
387 summary.Pending += countByState.Count
388 }
389 }
390
391 return summary
392 }
393
394 // If we don't have the counts by state, then we'll need to summarise by looking at the more detailed contexts
395 for _, c := range contexts.Nodes {
396 // Nodes are a discriminated union of CheckRun or StatusContext and we can match on
397 // the TypeName to narrow the type.
398 if c.TypeName == "CheckRun" {
399 // https://docs.github.com/en/graphql/reference/enums#checkstatusstate
400 // If the status is completed then we can check the conclusion field
401 if c.Status == "COMPLETED" {
402 switch parseCheckStatusFromCheckConclusionState(c.Conclusion) {
403 case passing:
404 summary.Passing++
405 case failing:
406 summary.Failing++
407 default:
408 summary.Pending++
409 }
410 // otherwise we're in some form of pending state:
411 // "COMPLETED", "IN_PROGRESS", "PENDING", "QUEUED", "REQUESTED", "WAITING" or otherwise unknown
412 } else {
413 summary.Pending++
414 }