diff options
-rw-r--r-- | buildbot-client.el | 5 | ||||
-rw-r--r-- | buildbot-utils.el | 28 | ||||
-rw-r--r-- | buildbot-view.el | 65 |
3 files changed, 75 insertions, 23 deletions
diff --git a/buildbot-client.el b/buildbot-client.el index e979368..a633ff0 100644 --- a/buildbot-client.el +++ b/buildbot-client.el @@ -31,8 +31,9 @@ "%s/api/v2/builds/%s/steps" buildbot-host buildid))) -(defun buildbot-format-log-url (logid) - (format "%s/api/v2/logs/%s/raw" buildbot-host logid)) +(defun buildbot-api-log-raw (logid) + (buildbot-url-fetch-raw + (format "%s/api/v2/logs/%d/raw" buildbot-host logid))) (defun buildbot-api-recent-changes (limit) (buildbot-api-change (list (cons 'order "-changeid") (cons 'limit limit)))) diff --git a/buildbot-utils.el b/buildbot-utils.el index 3d4a901..d3b4a1e 100644 --- a/buildbot-utils.el +++ b/buildbot-utils.el @@ -41,9 +41,35 @@ (json-read))) (error "HTTP error: %s" (buffer-substring (point) (point-max))))))) +(defun buildbot-url-fetch-raw (url &optional decompression with-header) + (with-current-buffer (get-buffer-create buildbot-client-buffer-name) + (goto-char (point-max)) + (insert "[" (current-time-string) "] Request: " url "\n")) + (with-current-buffer (url-retrieve-synchronously url t) + (let ((header) (status) (fields)) + (buildbot-delete-http-header) + (goto-char (point-min)) + (setq header (buildbot-parse-http-header (car kill-ring)) + status (alist-get 'status header) + fields (alist-get 'fields header)) + (with-current-buffer buildbot-client-buffer-name + (insert "[" (current-time-string) "] Response: " status "\n")) + (when decompression + (call-process-region (point) (point-max) "gunzip" t t t) + (goto-char (point-min))) + (call-interactively 'delete-trailing-whitespace) + (if (string= status "200") + (unless (= (point) (point-max)) + (if with-header + (list + (cons 'header fields) + (cons 'json (buffer-string))) + (buffer-string))) + (error "HTTP error: %s" (buffer-substring (point) (point-max))))))) + (defun buildbot-format-attr (attr) (string-join (mapcar (lambda (pair) - (format "%s=%s" (car pair) (cdr pair))) + (format "%s=%s" (car pair) (cdr pair))) attr) "&")) diff --git a/buildbot-view.el b/buildbot-view.el index 7d1b677..12574cf 100644 --- a/buildbot-view.el +++ b/buildbot-view.el @@ -5,10 +5,6 @@ ;; '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") @@ -121,26 +117,42 @@ (buildbot-view-format-build build) "\n" (buildbot-view-format-step step) + "\n" (string-join (mapcar 'buildbot-view-format-log logs) "\n"))) +(defun buildbot-log-format (revision-info build step log log-text) + (concat + (buildbot-view-format-revision-info revision-info) + "\n" + (buildbot-view-format-build build) + "\n" + (buildbot-view-format-step step) + "\n" + (buildbot-view-format-log log) + "\n" + log-text)) + (defun buildbot-view-buffer-name (type data) (pcase type - ('revision (format "*buildbot revision %s" + ('revision (format "*buildbot revision %s*" (alist-get 'revision-id data))) - ('build (format "*buildbot build %d" + ('build (format "*buildbot build %d*" (alist-get 'id (alist-get 'build data)))) - ('step (format "*buildbot step %d" - (alist-get 'stepid (alist-get 'step data)))))) + ('step (format "*buildbot step %d*" + (alist-get 'stepid (alist-get 'step data)))) + ('log (format "*buildbot log %d*" + (alist-get 'logid (alist-get 'log data)))))) -(defun buildbot-view-load (type data) +(defun buildbot-view-open (type data &optional force) (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)) + (when (or force (not (get-buffer buffer-name))) + (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 () @@ -181,25 +193,38 @@ (alist-get 'step buildbot-view-data) (buildbot-get-logs-by-stepid (alist-get 'stepid - (alist-get 'step buildbot-view-data))))))) + (alist-get 'step buildbot-view-data)))))) + ('log + (insert (buildbot-log-format + (alist-get 'revision-info buildbot-view-data) + (alist-get 'build buildbot-view-data) + (alist-get 'step buildbot-view-data) + (alist-get 'log buildbot-view-data) + (buildbot-api-log-raw + (alist-get 'logid + (alist-get 'log buildbot-view-data))))))) (goto-char (point-min)))) -(defun buildbot-view-open-thing-at-point () - (interactive) +(defun buildbot-view-open-thing-at-point (force) + (interactive "P") (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)) + (buildbot-view-open 'revision data)) ('build (setf (alist-get 'build data) (get-text-property (point) 'build)) - (buildbot-view-load 'build data)) + (buildbot-view-open 'build data)) ('step (setf (alist-get 'step data) (get-text-property (point) 'step)) - (buildbot-view-load 'step data))))) + (buildbot-view-open 'step data)) + ('log + (setf (alist-get 'log data) + (get-text-property (point) 'log)) + (buildbot-view-open 'log data))))) (define-key buildbot-view-mode-map (kbd "<return>") 'buildbot-view-open-thing-at-point) |