aboutsummaryrefslogtreecommitdiff
path: root/buildbot-utils.el
diff options
context:
space:
mode:
authorYuchen Pei <hi@ypei.me>2023-03-26 19:02:17 +1100
committerYuchen Pei <hi@ypei.me>2023-03-26 19:02:17 +1100
commit9714d2e9b7510d002b0bbd4fd0d6b396a72fdf8b (patch)
tree27742be276784ed198d08eb29b577e4a153face8 /buildbot-utils.el
parenta7e313d116b059b23ddb6efa185e3606f1da75a8 (diff)
branch view (first imp); faces for status; revision with multiple changes
Diffstat (limited to 'buildbot-utils.el')
-rw-r--r--buildbot-utils.el53
1 files changed, 53 insertions, 0 deletions
diff --git a/buildbot-utils.el b/buildbot-utils.el
index d3b4a1e..e268e52 100644
--- a/buildbot-utils.el
+++ b/buildbot-utils.el
@@ -1,3 +1,4 @@
+;; -*- lexical-binding: t; -*-
(defun buildbot-parse-http-header (text)
(let ((status) (fields))
(with-temp-buffer
@@ -86,4 +87,56 @@
'failure)
(t 'pending))))
+(defun buildbot-step-guess-status (step)
+ (let ((state (alist-get 'state_string step)))
+ (cond ((string-suffix-p "(warnings)" state)
+ 'pending)
+ ((string-suffix-p "(failure)" state)
+ 'failure)
+ ((string-suffix-p "done" state)
+ 'success)
+ ((string-suffix-p "ing" state)
+ 'pending)
+ ((string-suffix-p "finished" state)
+ 'success)
+ (t 'success))))
+
+(defun buildbot-status-face (status)
+ (pcase status
+ ('success 'success)
+ ('failure 'error)
+ (_ 'warning)))
+
+(defun buildbot-get-build-stats (builds)
+ (let ((results (copy-tree '((success . 0)
+ (failure . 0)
+ (pending . 0))))
+ (status))
+ (seq-do
+ (lambda (build)
+ (setq status (buildbot-build-status build))
+ (setf (alist-get status results)
+ (1+ (alist-get status results))))
+ builds)
+ results))
+
+(defun buildbot-get-info-and-builds (changes)
+ "Get revision-info and builds from a set of changes of the same revision.
+
+Concat all builds."
+ (let* ((builds (seq-mapcat
+ (lambda (change)
+ (alist-get 'builds change))
+ changes))
+ (first-change (elt changes 0))
+ (info (list
+ (assq 'revision first-change)
+ (assq 'author first-change)
+ (cons 'created-at
+ (buildbot-format-epoch-time
+ (alist-get 'when_timestamp first-change)))
+ (assq 'comments first-change)
+ (cons 'build-stats (buildbot-get-build-stats builds)))))
+ `((revision-info . ,info) (builds . ,builds))))
+
(provide 'buildbot-utils)