blob: 78703ea59b6db95cab3ae4102825203128c33b96 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
|
;; -*- 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 "<return>")
'buildbot-revision-open-build)
(provide 'buildbot-revision)
|