From 20fd138b70a92fa3dc8a8a44e95fa2be57da092f Mon Sep 17 00:00:00 2001 From: Yuchen Pei Date: Sat, 25 Mar 2023 01:05:54 +1100 Subject: Unify the three modes into one (view mode) Also, now one can press return at any header to go to the respective object. For example, in step view, one can jump to the revision view by pressing return at the revision header on top --- buildbot-build.el | 61 ---------------------- buildbot-revision.el | 84 ----------------------------- buildbot-step.el | 54 ------------------- buildbot-view.el | 145 +++++++++++++++++++++++++++++++++++++++++++++++++-- buildbot.el | 3 +- 5 files changed, 142 insertions(+), 205 deletions(-) delete mode 100644 buildbot-build.el delete mode 100644 buildbot-revision.el delete mode 100644 buildbot-step.el diff --git a/buildbot-build.el b/buildbot-build.el deleted file mode 100644 index 9e3d913..0000000 --- a/buildbot-build.el +++ /dev/null @@ -1,61 +0,0 @@ -;; -*- lexical-binding: t; -*- -(require 'buildbot-client) -(require 'buildbot-view) - -(define-derived-mode buildbot-build-mode buildbot-view-mode "Buildbot build" - "Buildbot view for a build") - -(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 (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 build - buildbot-build-revision-info revision-info) - (buildbot-build-update)) - (switch-to-buffer buffer-name))) - -(defun buildbot-build-update () - (unless (derived-mode-p 'buildbot-build-mode) - (error "Not in buildbot build mode")) - (let ((inhibit-read-only t)) - (erase-buffer) - (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-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 "") - 'buildbot-build-open-step) - -(provide 'buildbot-build) diff --git a/buildbot-revision.el b/buildbot-revision.el deleted file mode 100644 index 78703ea..0000000 --- a/buildbot-revision.el +++ /dev/null @@ -1,84 +0,0 @@ -;; -*- lexical-binding: t; -*- -(require 'buildbot-client) -(require 'buildbot-view) - -(defvar-local buildbot-revision-revision-id nil) -(defvar-local buildbot-revision-info nil) - -(define-derived-mode buildbot-revision-mode buildbot-view-mode "Buildbot revision" - "Buildbot view for a revision") - -(defun buildbot-revision-buffer-name (revision) - (concat "*buildbot revision " revision "*")) - -(defun buildbot-revision-load (revision) - (let ((buffer-name (buildbot-revision-buffer-name revision))) - (with-current-buffer (get-buffer-create buffer-name) - (buildbot-revision-mode) - (setq buildbot-revision-revision-id revision) - (buildbot-revision-update)) - (switch-to-buffer buffer-name))) - -(defun buildbot-revision-update () - (unless (derived-mode-p 'buildbot-revision-mode) - (error "Not in buildbot revision mode")) - (let ((inhibit-read-only t)) - (erase-buffer) - (let ((change - (buildbot-get-change-by-revision buildbot-revision-revision-id))) - (setq buildbot-revision-info - (buildbot-revision-get-info change)) - (insert (buildbot-revision-format buildbot-revision-info - (alist-get 'builds change))) - (goto-char (point-min))))) - -(defun buildbot-revision-open (revision) - (interactive "sRevision (commit hash): ") - (buildbot-revision-load revision)) - -(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-view-format-revision-info revision-info) - "\n" - (string-join - (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)) - (cons 'build-stats (buildbot-revision-get-build-stats - (alist-get 'builds change))))) - -(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-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 "") - 'buildbot-revision-open-build) - -(provide 'buildbot-revision) diff --git a/buildbot-step.el b/buildbot-step.el deleted file mode 100644 index 1058410..0000000 --- a/buildbot-step.el +++ /dev/null @@ -1,54 +0,0 @@ -;; -*- 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-view.el b/buildbot-view.el index 846c0df..7d1b677 100644 --- a/buildbot-view.el +++ b/buildbot-view.el @@ -2,6 +2,13 @@ (require 'buildbot-utils) (defvar buildbot-view-header-regex "^\\[.*\\]$") +;; 'revision, 'build, 'step, or 'log +(defvar-local buildbot-view-type nil) +(defvar-local buildbot-view-data nil) +;; (defvar-local buildbot-view-revision-id nil) +;; (defvar-local buildbot-view-revision-info nil) +;; (defvar-local buildbot-view-build nil) +;; (defvar-local buildbot-view-step nil) (define-derived-mode buildbot-view-mode special-mode "Buildbot view" "Buildbot view, a base mode") @@ -33,7 +40,7 @@ (alist-get 'comments revision-info) (buildbot-view-format-build-stats (alist-get 'build-stats revision-info))) - 'revision-id (alist-get 'revision revision-info))) + 'revision-id (alist-get 'revision revision-info) 'type 'revision)) (defun buildbot-view-format-build-stats (stats) (format "Build stats: Success - %d | Failure - %d | Pending - %d" @@ -50,7 +57,7 @@ (mapcar (lambda (test) (alist-get 'test_name test)) (alist-get 'failed_tests build)) "\n")) - 'build build)) + 'build build 'type 'build)) (defun buildbot-view-format-step (step) (propertize @@ -58,12 +65,142 @@ (alist-get 'number step) (alist-get 'name step) (alist-get 'state_string step)) - 'step step)) + 'step step 'type 'step)) (defun buildbot-view-format-log (log) (propertize (format "\n[%s]\n" (alist-get 'name log)) - 'log log)) + 'log log 'type 'log)) + +(defun buildbot-revision-format (revision-info builds) + (concat + (buildbot-view-format-revision-info revision-info) + "\n" + (string-join + (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)) + (cons 'build-stats (buildbot-revision-get-build-stats + (alist-get 'builds change))))) + +(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-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-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"))) + +(defun buildbot-view-buffer-name (type data) + (pcase type + ('revision (format "*buildbot revision %s" + (alist-get 'revision-id data))) + ('build (format "*buildbot build %d" + (alist-get 'id (alist-get 'build data)))) + ('step (format "*buildbot step %d" + (alist-get 'stepid (alist-get 'step data)))))) + +(defun buildbot-view-load (type data) + (let ((buffer-name (buildbot-view-buffer-name type data))) + (with-current-buffer (get-buffer-create buffer-name) + (buildbot-view-mode) + (setq buildbot-view-type type + buildbot-view-data data) + (buildbot-view-update)) + (switch-to-buffer buffer-name))) + +(defun buildbot-view-reload () + (interactive) + (buildbot-view-update)) +(define-key buildbot-view-mode-map "g" 'buildbot-view-reload) + +(defun buildbot-view-revision-open (revision-id) + (interactive "sRevision (commit hash): ") + (buildbot-view-load 'revision `((revision-id . ,revision-id)))) + +(defun buildbot-view-update () + (unless (derived-mode-p 'buildbot-view-mode) + (error "Not in buildbot view mode")) + (let ((inhibit-read-only t)) + (erase-buffer) + (pcase buildbot-view-type + ('revision + (let ((change + (buildbot-get-change-by-revision + (alist-get 'revision-id buildbot-view-data)))) + (setf (alist-get 'revision-info buildbot-view-data) + (buildbot-revision-get-info change)) + (insert (buildbot-revision-format + (alist-get 'revision-info buildbot-view-data) + (alist-get 'builds change))))) + ('build + (insert (buildbot-build-format + (alist-get 'revision-info buildbot-view-data) + (alist-get 'build buildbot-view-data) + (buildbot-get-steps-by-buildid + (alist-get 'id + (alist-get 'build buildbot-view-data)))))) + ('step + (insert (buildbot-step-format + (alist-get 'revision-info buildbot-view-data) + (alist-get 'build buildbot-view-data) + (alist-get 'step buildbot-view-data) + (buildbot-get-logs-by-stepid + (alist-get 'stepid + (alist-get 'step buildbot-view-data))))))) + (goto-char (point-min)))) + +(defun buildbot-view-open-thing-at-point () + (interactive) + (let ((data (copy-tree buildbot-view-data))) + (pcase (get-text-property (point) 'type) + ('revision + (setf (alist-get 'revision-id data) + (get-text-property (point) 'revision-id)) + (buildbot-view-load 'revision data)) + ('build + (setf (alist-get 'build data) + (get-text-property (point) 'build)) + (buildbot-view-load 'build data)) + ('step + (setf (alist-get 'step data) + (get-text-property (point) 'step)) + (buildbot-view-load 'step data))))) +(define-key buildbot-view-mode-map (kbd "") + 'buildbot-view-open-thing-at-point) (provide 'buildbot-view) diff --git a/buildbot.el b/buildbot.el index e66c4a7..e799410 100644 --- a/buildbot.el +++ b/buildbot.el @@ -4,7 +4,6 @@ (require 'buildbot-client) (defvar buildbot-builders (buildbot-get-all-builders)) -(require 'buildbot-revision) -(require 'buildbot-build) +(require 'buildbot-view) (provide 'buildbot) -- cgit v1.2.3