aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--buildbot-build.el64
-rw-r--r--buildbot-client.el5
-rw-r--r--buildbot-revision.el73
-rw-r--r--buildbot-step.el54
-rw-r--r--buildbot-utils.el9
-rw-r--r--buildbot-view.el69
-rw-r--r--buildbot.el4
7 files changed, 209 insertions, 69 deletions
diff --git a/buildbot-build.el b/buildbot-build.el
index a6c2b09..9e3d913 100644
--- a/buildbot-build.el
+++ b/buildbot-build.el
@@ -1,17 +1,21 @@
+;; -*- lexical-binding: t; -*-
(require 'buildbot-client)
-(define-derived-mode buildbot-build-mode special-mode "Buildbot build"
+(require 'buildbot-view)
+
+(define-derived-mode buildbot-build-mode buildbot-view-mode "Buildbot build"
"Buildbot view for a build")
-(defvar-local buildbot-build-build-id nil)
-(defvar-local buildbot-build-info nil)
+(defvar-local buildbot-build-build nil)
+(defvar-local buildbot-build-revision-info nil)
(defun buildbot-build-buffer-name (buildid)
(concat "*buildbot build " (number-to-string buildid) "*"))
-(defun buildbot-build-load (buildid)
- (let ((buffer-name (buildbot-build-buffer-name buildid)))
+(defun buildbot-build-load (build revision-info)
+ (let ((buffer-name (buildbot-build-buffer-name (alist-get 'id build))))
(with-current-buffer (get-buffer-create buffer-name)
(buildbot-build-mode)
- (setq buildbot-build-build-id buildid)
+ (setq buildbot-build-build build
+ buildbot-build-revision-info revision-info)
(buildbot-build-update))
(switch-to-buffer buffer-name)))
@@ -20,24 +24,38 @@
(error "Not in buildbot build mode"))
(let ((inhibit-read-only t))
(erase-buffer)
- (let ((steps (buildbot-get-steps-by-buildid buildbot-build-build-id)))
- (insert (buildbot-build-format steps))
+ (let ((steps (buildbot-get-steps-by-buildid
+ (alist-get 'id buildbot-build-build))))
+ (insert (buildbot-build-format
+ buildbot-build-revision-info
+ buildbot-build-build
+ steps))
(goto-char (point-min)))))
-(defun buildbot-build-open (buildid)
- (interactive "sBuildi ID: ")
- (buildbot-build-load (string-to-number buildid)))
-
-(defun buildbot-build-format (steps)
- (string-join
- (mapcar 'buildbot-build-format-step steps)
- "\n"))
-
-(defun buildbot-build-format-step (step)
- (propertize
- (format "\n[%d %s %s]\n"
- (alist-get 'number step)
- (alist-get 'name step)
- (alist-get 'state_string step))))
+(defun buildbot-build-reload ()
+ (interactive)
+ (buildbot-build-update))
+(define-key buildbot-build-mode-map "g" 'buildbot-build-reload)
+
+(defun buildbot-build-format (revision-info build steps)
+ (concat
+ (buildbot-view-format-revision-info revision-info)
+ "\n"
+ (buildbot-view-format-build build)
+ "\n"
+ (string-join
+ (mapcar 'buildbot-view-format-step steps)
+ "\n")))
+
+(defun buildbot-build-open-step ()
+ (interactive)
+ (let ((step (get-text-property (point) 'step)))
+ (unless step
+ (error "Not at a step"))
+ (buildbot-step-load buildbot-build-revision-info
+ buildbot-build-build
+ step)))
+(define-key buildbot-build-mode-map (kbd "<return>")
+ 'buildbot-build-open-step)
(provide 'buildbot-build)
diff --git a/buildbot-client.el b/buildbot-client.el
index afc1a69..e979368 100644
--- a/buildbot-client.el
+++ b/buildbot-client.el
@@ -10,7 +10,7 @@
(defun buildbot-api-logs (stepid)
(buildbot-url-fetch-json
(format
- "%s/api/v2/steps/%s/logs"
+ "%s/api/v2/steps/%d/logs"
buildbot-host stepid)))
(defun buildbot-api-builders ()
@@ -46,6 +46,9 @@
(= (alist-get 'builderid builder) builderid))
buildbot-builders))
+(defun buildbot-get-logs-by-stepid (stepid)
+ (alist-get 'logs (buildbot-api-logs stepid)))
+
(defun buildbot-get-builder-name-by-id (id)
(alist-get 'name (buildbot-builder-by-id id)))
diff --git a/buildbot-revision.el b/buildbot-revision.el
index 08ba7b1..78703ea 100644
--- a/buildbot-revision.el
+++ b/buildbot-revision.el
@@ -1,15 +1,13 @@
;; -*- lexical-binding: t; -*-
(require 'buildbot-client)
+(require 'buildbot-view)
(defvar-local buildbot-revision-revision-id nil)
(defvar-local buildbot-revision-info nil)
-(defvar buildbot-revision-header-regex "^\\[.*\\]$")
-(define-derived-mode buildbot-revision-mode special-mode "Buildbot revision"
+(define-derived-mode buildbot-revision-mode buildbot-view-mode "Buildbot revision"
"Buildbot view for a revision")
-(define-key buildbot-revision-mode-map "g" 'buildbot-revision-reload)
-
(defun buildbot-revision-buffer-name (revision)
(concat "*buildbot revision " revision "*"))
@@ -41,57 +39,46 @@
(defun buildbot-revision-reload ()
(interactive)
(buildbot-revision-update))
+(define-key buildbot-revision-mode-map "g" 'buildbot-revision-reload)
(defun buildbot-revision-format (revision-info builds)
(concat
- (buildbot-revision-format-info revision-info)
+ (buildbot-view-format-revision-info revision-info)
"\n"
(string-join
- (mapcar 'buildbot-revision-format-build builds)
+ (mapcar 'buildbot-view-format-build builds)
"\n")))
(defun buildbot-revision-get-info (change)
(list (cons 'revision (alist-get 'revision change))
(cons 'author (alist-get 'author change))
(cons 'created-at (buildbot-format-epoch-time
- (alist-get 'created_at
- (alist-get 'sourcestamp change))))
- (cons 'comments (alist-get 'comments change))))
+ (alist-get 'created_at
+ (alist-get 'sourcestamp change))))
+ (cons 'comments (alist-get 'comments change))
+ (cons 'build-stats (buildbot-revision-get-build-stats
+ (alist-get 'builds change)))))
-(defun buildbot-revision-format-info (info)
- (format
- "commit %s\nAuthor: %s\nDate: %s\n\n%s"
- (alist-get 'revision info)
- (alist-get 'author info)
- (alist-get 'created-at info)
- (alist-get 'comments info)))
+(defun buildbot-revision-get-build-stats (builds)
+ (let ((results '((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-revision-next-header (n)
- (interactive "p")
- (dotimes (_ n)
- (end-of-line 1)
- (re-search-forward buildbot-revision-header-regex)
- (beginning-of-line 1)))
-(define-key buildbot-revision-mode-map "n" 'buildbot-revision-next-header)
-
-(defun buildbot-revision-previous-header (n)
- (interactive "p")
- (beginning-of-line 1)
- (unless (looking-at buildbot-revision-header-regex)
- (re-search-backward buildbot-revision-header-regex))
- (dotimes (_ n)
- (re-search-backward buildbot-revision-header-regex)))
-(define-key buildbot-revision-mode-map "p" 'buildbot-revision-previous-header)
-
-(defun buildbot-revision-format-build (build)
- (propertize
- (format "\n[%s %s]\n%s"
- (buildbot-get-builder-name-by-id (alist-get 'builderid build))
- (alist-get 'state_string build)
- (string-join
- (mapcar (lambda (test) (alist-get 'test_name test))
- (alist-get 'failed_tests build))
- "\n"))
- 'buildid (alist-get 'id build)))
+(defun buildbot-revision-open-build ()
+ (interactive)
+ (let ((build (get-text-property (point) 'build)))
+ (unless build
+ (error "Not at a build"))
+ (buildbot-build-load build buildbot-revision-info)))
+(define-key buildbot-revision-mode-map (kbd "<return>")
+ 'buildbot-revision-open-build)
(provide 'buildbot-revision)
diff --git a/buildbot-step.el b/buildbot-step.el
new file mode 100644
index 0000000..1058410
--- /dev/null
+++ b/buildbot-step.el
@@ -0,0 +1,54 @@
+;; -*- lexical-binding: t; -*-
+(require 'buildbot-client)
+(require 'buildbot-view)
+
+(define-derived-mode buildbot-step-mode buildbot-view-mode "Buildbot step"
+ "Buildbot view for a step")
+
+(defvar-local buildbot-step-revision-info nil)
+(defvar-local buildbot-step-build nil)
+(defvar-local buildbot-step-step nil)
+(defun buildbot-step-buffer-name (stepid)
+ (concat "*buildbot step " (number-to-string stepid) "*"))
+
+(defun buildbot-step-load (revision-info build step)
+ (let ((buffer-name (buildbot-step-buffer-name (alist-get 'stepid step))))
+ (with-current-buffer (get-buffer-create buffer-name)
+ (buildbot-step-mode)
+ (setq buildbot-step-revision-info revision-info
+ buildbot-step-build build
+ buildbot-step-step step)
+ (buildbot-step-update))
+ (switch-to-buffer buffer-name)))
+
+(defun buildbot-step-update ()
+ (unless (derived-mode-p 'buildbot-step-mode)
+ (error "Not in buildbot step mode"))
+ (let ((inhibit-read-only t))
+ (erase-buffer)
+ (let ((logs (buildbot-get-logs-by-stepid
+ (alist-get 'stepid buildbot-step-step))))
+ (insert (buildbot-step-format
+ buildbot-step-revision-info
+ buildbot-step-build
+ buildbot-step-step
+ logs))
+ (goto-char (point-min)))))
+
+(defun buildbot-step-reload ()
+ (interactive)
+ (buildbot-step-update))
+(define-key buildbot-step-mode-map "g" 'buildbot-step-reload)
+
+(defun buildbot-step-format (revision-info build step logs)
+ (concat
+ (buildbot-view-format-revision-info revision-info)
+ "\n"
+ (buildbot-view-format-build build)
+ "\n"
+ (buildbot-view-format-step step)
+ (string-join
+ (mapcar 'buildbot-view-format-log logs)
+ "\n")))
+
+(provide 'buildbot-step)
diff --git a/buildbot-utils.el b/buildbot-utils.el
index 269cdf3..3d4a901 100644
--- a/buildbot-utils.el
+++ b/buildbot-utils.el
@@ -51,4 +51,13 @@
(format-time-string "%Y-%m-%d %a %H:%M:%S %Z" (encode-time
(decode-time epoch))))
+
+(defun buildbot-build-status (build)
+ (let ((state (alist-get 'state_string build)))
+ (cond ((equal state "build successful")
+ 'success)
+ ((string-suffix-p "(failure)" state)
+ 'failure)
+ (t 'pending))))
+
(provide 'buildbot-utils)
diff --git a/buildbot-view.el b/buildbot-view.el
new file mode 100644
index 0000000..846c0df
--- /dev/null
+++ b/buildbot-view.el
@@ -0,0 +1,69 @@
+;; -*- lexical-binding: t; -*-
+(require 'buildbot-utils)
+
+(defvar buildbot-view-header-regex "^\\[.*\\]$")
+
+(define-derived-mode buildbot-view-mode special-mode "Buildbot view"
+ "Buildbot view, a base mode")
+
+(defun buildbot-view-next-header (n)
+ (interactive "p")
+ (dotimes (_ n)
+ (end-of-line 1)
+ (re-search-forward buildbot-view-header-regex)
+ (beginning-of-line 1)))
+(define-key buildbot-view-mode-map "n" 'buildbot-view-next-header)
+
+(defun buildbot-view-previous-header (n)
+ (interactive "p")
+ (beginning-of-line 1)
+ (unless (looking-at buildbot-view-header-regex)
+ (re-search-backward buildbot-view-header-regex))
+ (dotimes (_ n)
+ (re-search-backward buildbot-view-header-regex)))
+(define-key buildbot-view-mode-map "p" 'buildbot-view-previous-header)
+
+(defun buildbot-view-format-revision-info (revision-info)
+ (propertize
+ (format
+ "[commit %s]\nAuthor: %s\nDate: %s\n\n%s\n\n%s"
+ (alist-get 'revision revision-info)
+ (alist-get 'author revision-info)
+ (alist-get 'created-at revision-info)
+ (alist-get 'comments revision-info)
+ (buildbot-view-format-build-stats
+ (alist-get 'build-stats revision-info)))
+ 'revision-id (alist-get 'revision revision-info)))
+
+(defun buildbot-view-format-build-stats (stats)
+ (format "Build stats: Success - %d | Failure - %d | Pending - %d"
+ (alist-get 'success stats)
+ (alist-get 'failure stats)
+ (alist-get 'pending stats)))
+
+(defun buildbot-view-format-build (build)
+ (propertize
+ (format "\n[%s %s]\n%s"
+ (buildbot-get-builder-name-by-id (alist-get 'builderid build))
+ (alist-get 'state_string build)
+ (string-join
+ (mapcar (lambda (test) (alist-get 'test_name test))
+ (alist-get 'failed_tests build))
+ "\n"))
+ 'build build))
+
+(defun buildbot-view-format-step (step)
+ (propertize
+ (format "\n[%d %s %s]\n"
+ (alist-get 'number step)
+ (alist-get 'name step)
+ (alist-get 'state_string step))
+ 'step step))
+
+(defun buildbot-view-format-log (log)
+ (propertize
+ (format "\n[%s]\n"
+ (alist-get 'name log))
+ 'log log))
+
+(provide 'buildbot-view)
diff --git a/buildbot.el b/buildbot.el
index 7c62017..e66c4a7 100644
--- a/buildbot.el
+++ b/buildbot.el
@@ -1,10 +1,10 @@
;; -*- lexical-binding: t; -*-
-(defvar buildbot-builders (buildbot-get-all-builders))
(defvar buildbot-client-buffer-name "*buildbot api*")
(defvar buildbot-host nil)
+(require 'buildbot-client)
+(defvar buildbot-builders (buildbot-get-all-builders))
(require 'buildbot-revision)
(require 'buildbot-build)
-(require 'buildbot-client)
(provide 'buildbot)