Subject: [PATCH] Fix templates to handle all statuses.

From: Robert Vollmert <[email-masked]>
Date: Wed, 31 Jul 2019 16:48:50 +0200

* src/cuirass/templates.scm: Factor out class and title helpers
for build statuses, and handle all the statuses.
---
 src/cuirass/templates.scm | 109 ++++++++++++--------------------------
 1 file changed, 33 insertions(+), 76 deletions(-)

diff --git a/src/cuirass/templates.scm b/src/cuirass/templates.scm
index ab1b85c..84097f0 100644
--- a/src/cuirass/templates.scm
+++ b/src/cuirass/templates.scm
@@ -103,6 +103,28 @@
                 ,body
                 (hr)))))
 
+(define (status-class status)
+  (cond
+    ((= (build-status scheduled)         status) "oi oi-clock         text-warning")
+    ((= (build-status started)           status) "oi oi-reload        text-warning")
+    ((= (build-status succeeded)         status) "oi oi-check         text-success")
+    ((= (build-status failed)            status) "oi oi-x             text-danger")
+    ((= (build-status failed-dependency) status) "oi oi-warning       text-danger")
+    ((= (build-status failed-other)      status) "oi oi-warning       text-danger")
+    ((= (build-status canceled)          status) "oi oi-question-mark text-warning")
+    (else                                        "oi oi-warning       text-danger")))
+
+(define (status-title status)
+  (cond
+    ((= (build-status scheduled)         status) "Scheduled")
+    ((= (build-status started)           status) "Started")
+    ((= (build-status succeeded)         status) "Succeeded")
+    ((= (build-status failed)            status) "Failed")
+    ((= (build-status failed-dependency) status) "Failed (dependency)")
+    ((= (build-status failed-other)      status) "Failed (other)")
+    ((= (build-status canceled)          status) "Canceled")
+    (else                                        "Invalid status")))
+
 (define (specifications-table specs)
   "Return HTML for the SPECS table."
   `((p (@ (class "lead")) "Specifications")
@@ -128,29 +150,6 @@
 (define (build-details build)
   "Return HTML showing details for the BUILD."
   (define status (assq-ref build #:status))
-  (define display-status
-    (cond
-     ((= (build-status succeeded) status)
-      `(span (@ (class "oi oi-check text-success")
-                (title "Succeeded"))
-             " Success"))
-     ((= (build-status scheduled) status)
-      `(span (@ (class "oi oi-clock text-warning")
-                (title "Scheduled")
-                (aria-hidden "true"))
-             " Scheduled"))
-     ((= (build-status canceled) status)
-      `(span (@ (class "oi oi-question-mark text-warning")
-                (title "Canceled"))
-             " Canceled"))
-     ((= (build-status failed-dependency) status)
-      `(span (@ (class "oi oi-warning text-danger")
-                (title "Dependency failed"))
-             " Dependency failed"))
-     (else
-      `(span (@ (class "oi oi-x text-danger")
-                (title "Failed"))
-             " Failed"))))
   (define blocking-outputs
     (or (and-let* (((= (build-status failed-dependency) status))
                    (drv (false-if-exception
@@ -172,7 +171,9 @@
       (tr (th "Build ID")
           (td ,(assq-ref build #:id)))
       (tr (th "Status")
-          (td ,display-status
+          (td (span (@ (class ,(status-class status))
+                       (title ,(status-title status)))
+                ,(string-append " " (status-title status)))
               ,@(map (lambda (output)
                        `((br)
                          (a (@ (href ,(string-append "/log/" (basename output))))
@@ -361,32 +362,10 @@ and BUILD-MAX are global minimal and maximal (stoptime, rowid) pairs."
           (= (build-status failed) status)))
 
     `(tr
-      (td ,(cond
-            ((= (build-status succeeded) status)
-             `(span (@ (class "oi oi-check text-success")
-                       (title "Succeeded")
-                       (aria-hidden "true"))
-                    ""))
-            ((= (build-status scheduled) status)
-             `(span (@ (class "oi oi-clock text-warning")
-                       (title "Scheduled")
-                       (aria-hidden "true"))
-                    ""))
-            ((= (build-status canceled) status)
-             `(span (@ (class "oi oi-question-mark text-warning")
-                       (title "Canceled")
-                       (aria-hidden "true"))
-                    ""))
-            ((= (build-status failed-dependency) status)
-             `(span (@ (class "oi oi-warning text-danger")
-                       (title "Dependency failed")
-                       (aria-hidden "true"))
-                    ""))
-            (else
-             `(span (@ (class "oi oi-x text-danger")
-                       (title "Failed")
-                       (aria-hidden "true"))
-                    ""))))
+      (td (span (@ (class ,(status-class status))
+                   (title ,(status-title status))
+                   (aria-hidden "true"))
+                ""))
       (th (@ (scope "row"))
           (a (@ (href "/build/" ,(assq-ref build #:id) "/details"))
              ,(assq-ref build #:id)))
@@ -474,32 +453,10 @@ and BUILD-MAX are global minimal and maximal row identifiers."
           (= (build-status failed) status)))
 
     `(tr
-      (td ,(cond
-            ((= (build-status succeeded) status)
-             `(span (@ (class "oi oi-check text-success")
-                       (title "Succeeded")
-                       (aria-hidden "true"))
-                    ""))
-            ((= (build-status scheduled) status)
-             `(span (@ (class "oi oi-clock text-warning")
-                       (title "Scheduled")
-                       (aria-hidden "true"))
-                    ""))
-            ((= (build-status canceled) status)
-             `(span (@ (class "oi oi-question-mark text-warning")
-                       (title "Canceled")
-                       (aria-hidden "true"))
-                    ""))
-            ((= (build-status failed-dependency) status)
-             `(span (@ (class "oi oi-warning text-danger")
-                       (title "Dependency failed")
-                       (aria-hidden "true"))
-                    ""))
-            (else
-             `(span (@ (class "oi oi-x text-danger")
-                       (title "Failed")
-                       (aria-hidden "true"))
-                    ""))))
+      (td (span (@ (class ,(status-class status))
+                   (title ,(status-title status))
+                   (aria-hidden "true"))
+                ""))
       (th (@ (scope "row"))
           (a (@ (href "/build/" ,(assq-ref build #:id) "/details"))
              ,(assq-ref build #:id)))
-- 
2.21.0