about summary refs log tree commit diff
path: root/ops/gerrit-tvl/static
diff options
context:
space:
mode:
authorVincent Ambo <mail@tazj.in>2022-01-14T20·10+0300
committerclbot <clbot@tvl.fyi>2022-01-14T20·30+0000
commite1ffaee1dd0cc954f084fcdd5fd30547956cf4c6 (patch)
tree463e60967a453b774e03b054e4cf64156e81aad0 /ops/gerrit-tvl/static
parent058bf61193f166f34d3dc4b6629a691b70d43142 (diff)
fix(gerrit-tvl): Support all documented Buildkite job statuses r/3594
I'm not sure where the previous list originated, but it was missing
some officially documented statuses. However, the API definitely
returns statuses that are documented to only appear in other types, so
this commit simply maps ALL statuses that Buildkite has documented for
any type.

Also adds a log statement in case we encounter a brand new, unknown,
undocumented status.

Change-Id: Iff003a3bd2608702019ae0f4137958435ad0856f
Reviewed-on: https://cl.tvl.fyi/c/depot/+/4888
Autosubmit: tazjin <tazjin@tvl.su>
Tested-by: BuildkiteCI
Reviewed-by: lukegb <lukegb@tvl.fyi>
Diffstat (limited to 'ops/gerrit-tvl/static')
-rw-r--r--ops/gerrit-tvl/static/tvl.js70
1 files changed, 58 insertions, 12 deletions
diff --git a/ops/gerrit-tvl/static/tvl.js b/ops/gerrit-tvl/static/tvl.js
index 2f8db90945ed..f4592ef44b1e 100644
--- a/ops/gerrit-tvl/static/tvl.js
+++ b/ops/gerrit-tvl/static/tvl.js
@@ -24,6 +24,59 @@ function formatDuration(from, to) {
   return `${hoursTook}hr ${minutesRemainder}min`;
 }
 
+// Maps the status of a Buildkite *job* to the statuses available for
+// a Gerrit check.
+//
+// Note that jobs can have statuses that, according to the Buildkite
+// documentation, are only available for builds, and maybe vice-versa.
+// To deal with this we simply cover all statuses for all types here.
+//
+// Buildkite job statuses: https://buildkite.com/docs/pipelines/notifications#job-states
+//
+// Gerrit check statuses: https://gerrit.googlesource.com/gerrit/+/v3.4.0/polygerrit-ui/app/api/checks.ts#167
+//
+// TODO(tazjin): Use SCHEDULED status once we have upgraded Gerrit
+// past 3.4
+function jobStateToCheckRunStatus(state) {
+  const status = {
+    // Statuses documented for both types
+    'blocked': 'RUNNABLE',
+    'canceled': 'COMPLETED',
+    'canceling': 'RUNNING',
+    'running': 'RUNNING',
+    'scheduled': 'RUNNABLE',
+    'skipped': 'COMPLETED',
+
+    // Statuses only documented for builds
+    'creating': 'RUNNABLE',
+    'failed': 'COMPLETED',
+    'not_run': 'COMPLETED',
+    'passed': 'COMPLETED',
+
+    // Statuses only documented for jobs
+    'accepted': 'RUNNABLE',
+    'assigned': 'RUNNABLE',
+    'blocked_failed': 'COMPLETED',
+    'broken': 'COMPLETED',
+    'finished': 'COMPLETED',
+    'limited': 'RUNNABLE',
+    'limiting': 'RUNNABLE',
+    'pending': 'RUNNABLE',
+    'timed_out': 'COMPLETED',
+    'timing_out': 'RUNNING',
+    'unblocked': 'RUNNABLE',
+    'unblocked_failed': 'COMPLETED',
+    'waiting': 'RUNNABLE',
+    'waiting_failed': 'COMPLETED',
+  }[state];
+
+  if (!status) {
+    console.log(`unknown Buildkite job state: ${state}`);
+  }
+
+  return status;
+}
+
 const tvlChecksProvider = {
   async fetch(change) {
     let {changeNumber, patchsetNumber, repo} = change;
@@ -58,32 +111,25 @@ const tvlChecksProvider = {
       const build = respJSON[i];
 
       for (let job of build.jobs) {
-        // TODO(lukegb): add the ability to retry these (sometimes whitby runs out of disk...)
+        // TODO(lukegb): add the ability to retry these
         const checkRun = {
           attempt: attempt,
           externalId: job.id,
           checkName: job.name,
           checkDescription: job.command,
           checkLink: job.web_url,
-          status: {
-            'running': 'RUNNING',
-            'scheduled': 'RUNNABLE',
-            'passed': 'COMPLETED',
-            'failed': 'COMPLETED',
-            'blocked': 'RUNNABLE',
-            'canceled': 'COMPLETED',
-            'canceling': 'RUNNING',
-            'skipped': 'COMPLETED',
-            'not_run': 'COMPLETED',
-          }[job.state],
+          status: jobStateToCheckRunStatus(job.state),
           labelName: 'Verified',
         };
+
         if (job.scheduled_at) {
           checkRun.scheduledTimestamp = new Date(job.scheduled_at);
         }
+
         if (job.started_at) {
           checkRun.startedTimestamp = new Date(job.started_at);
         }
+
         if (job.finished_at) {
           checkRun.finishedTimestamp = new Date(job.finished_at);
         }