From c4bb344dddc7b0cd805c28cdc5eb47404a8c2cb1 Mon Sep 17 00:00:00 2001 From: William Martin Date: Tue, 16 May 2023 19:41:59 +0200 Subject: [PATCH] Add some comments to PR ChecksStatus --- api/queries_pr.go | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/api/queries_pr.go b/api/queries_pr.go index ae8f7c0c6..5ae5cbb8f 100644 --- a/api/queries_pr.go +++ b/api/queries_pr.go @@ -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++