From 9714d2e9b7510d002b0bbd4fd0d6b396a72fdf8b Mon Sep 17 00:00:00 2001 From: Yuchen Pei Date: Sun, 26 Mar 2023 19:02:17 +1100 Subject: branch view (first imp); faces for status; revision with multiple changes --- buildbot-utils.el | 53 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) (limited to 'buildbot-utils.el') 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) -- cgit v1.2.3