From 94172a6c655ea4aefe2960aa5db9fec77130e87d Mon Sep 17 00:00:00 2001 From: Yuchen Pei Date: Fri, 24 Mar 2023 00:08:42 +1100 Subject: Adding step mode. Also refactoring --- buildbot-view.el | 69 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 69 insertions(+) create mode 100644 buildbot-view.el (limited to 'buildbot-view.el') 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) -- cgit v1.2.3