Add some comments to PR ChecksStatus

This commit is contained in:
William Martin 2023-05-16 19:41:59 +02:00
parent cd8547b227
commit c4bb344ddd

View file

@ -265,11 +265,17 @@ func (pr *PullRequest) ChecksStatus() (summary PullRequestChecksStatus) {
if len(pr.StatusCheckRollup.Nodes) == 0 {
return
}
commit := pr.StatusCheckRollup.Nodes[0].Commit
for _, c := range commit.StatusCheckRollup.Contexts.Nodes {
state := c.State // StatusContext
// Nodes are a discriminated union of CheckRun or StatusContext,
// but we can use the State field to disambiguate, rather than using the TypeName.
// First we try to get the State, as if we have a StatusContext
state := c.State
// But if the State is empty, then we assume we actually have a CheckRun
if state == "" {
// CheckRun
// If the Status of a CheckRun is COMPLETED, then we want to look more closely
// at the Conclusion, as that contains the relevant information.
if c.Status == "COMPLETED" {
state = c.Conclusion
} else {
@ -281,7 +287,9 @@ func (pr *PullRequest) ChecksStatus() (summary PullRequestChecksStatus) {
summary.Passing++
case "ERROR", "FAILURE", "CANCELLED", "TIMED_OUT", "ACTION_REQUIRED":
summary.Failing++
default: // "EXPECTED", "REQUESTED", "WAITING", "QUEUED", "PENDING", "IN_PROGRESS", "STALE"
// We treat anything that isn't Passing or Failing as Pending, which included any future unknown states
// we might get back from the API.
default: // "EXPECTED", "REQUESTED", "WAITING", "QUEUED", "PENDING", "IN_PROGRESS", "STALE", "STARTUP_FAILURE"
summary.Pending++
}
summary.Total++