MCPcopy Create free account
hub / github.com/github/gh-aw / classifyCheckState

Function classifyCheckState

pkg/cli/checks_command.go:333–383  ·  view source on GitHub ↗

classifyCheckState derives a normalized CheckState from raw check runs and commit statuses.

(checkRuns []PRCheckRun, statuses []PRCommitStatus)

Source from the content-addressed store, hash-verified

331
332// classifyCheckState derives a normalized CheckState from raw check runs and commit statuses.
333func classifyCheckState(checkRuns []PRCheckRun, statuses []PRCommitStatus) CheckState {
334 if len(checkRuns) == 0 && len(statuses) == 0 {
335 return CheckStateNoChecks
336 }
337
338 hasPending := false
339 hasFailed := false
340 hasPolicyBlocked := false
341
342 for _, cr := range checkRuns {
343 switch cr.Status {
344 case "queued", "in_progress", "waiting", "requested", "pending":
345 hasPending = true
346 case "completed":
347 switch cr.Conclusion {
348 case "failure", "timed_out", "startup_failure":
349 if isPolicyCheck(cr.Name) {
350 hasPolicyBlocked = true
351 } else {
352 hasFailed = true
353 }
354 case "action_required":
355 hasPolicyBlocked = true
356 }
357 }
358 }
359
360 for _, s := range statuses {
361 switch s.State {
362 case "pending":
363 hasPending = true
364 case "failure", "error":
365 if isPolicyCheck(s.Context) {
366 hasPolicyBlocked = true
367 } else {
368 hasFailed = true
369 }
370 }
371 }
372
373 switch {
374 case hasPolicyBlocked && !hasFailed && !hasPending:
375 return CheckStatePolicyBlocked
376 case hasFailed:
377 return CheckStateFailed
378 case hasPending:
379 return CheckStatePending
380 default:
381 return CheckStateSuccess
382 }
383}
384
385// printChecksJSON prints the result as JSON to stdout.
386func printChecksJSON(result *ChecksResult) error {

Callers 3

FetchChecksResultFunction · 0.85
TestClassifyCheckStateFunction · 0.85

Calls 1

isPolicyCheckFunction · 0.85

Tested by 2

TestClassifyCheckStateFunction · 0.68