zlib: Protect against non-empty port internal buffers.
[jackhill/guix/guix.git] / emacs / guix-hydra-jobset.el
1 ;;; guix-hydra-jobset.el --- Interface for Hydra jobsets -*- lexical-binding: t -*-
2
3 ;; Copyright © 2015 Alex Kost <alezost@gmail.com>
4
5 ;; This file is part of GNU Guix.
6
7 ;; GNU Guix is free software; you can redistribute it and/or modify
8 ;; it under the terms of the GNU General Public License as published by
9 ;; the Free Software Foundation, either version 3 of the License, or
10 ;; (at your option) any later version.
11
12 ;; GNU Guix is distributed in the hope that it will be useful,
13 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
14 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 ;; GNU General Public License for more details.
16
17 ;; You should have received a copy of the GNU General Public License
18 ;; along with this program. If not, see <http://www.gnu.org/licenses/>.
19
20 ;;; Commentary:
21
22 ;; This file provides an interface for displaying Hydra jobsets in
23 ;; 'list' and 'info' buffers.
24
25 ;;; Code:
26
27 (require 'cl-lib)
28 (require 'guix-buffer)
29 (require 'guix-list)
30 (require 'guix-info)
31 (require 'guix-hydra)
32 (require 'guix-hydra-build)
33 (require 'guix-utils)
34
35 (guix-hydra-define-entry-type hydra-jobset
36 :search-types '((project . guix-hydra-jobset-api-url))
37 :filters '(guix-hydra-jobset-filter-id)
38 :filter-names '((nrscheduled . scheduled)
39 (nrsucceeded . succeeded)
40 (nrfailed . failed)
41 (nrtotal . total)))
42
43 (defun guix-hydra-jobset-get-display (search-type &rest args)
44 "Search for Hydra builds and show results."
45 (apply #'guix-list-get-display-entries
46 'hydra-jobset search-type args))
47
48 \f
49 ;;; Defining URLs
50
51 (defun guix-hydra-jobset-url (project jobset)
52 "Return Hydra URL of a PROJECT's JOBSET."
53 (guix-hydra-url "jobset/" project "/" jobset))
54
55 (defun guix-hydra-jobset-api-url (project)
56 "Return Hydra API URL for jobsets by PROJECT."
57 (guix-hydra-api-url "jobsets"
58 `(("project" . ,project))))
59
60 \f
61 ;;; Filters for processing raw entries
62
63 (defun guix-hydra-jobset-filter-id (entry)
64 "Add 'ID' parameter to 'hydra-jobset' ENTRY."
65 (cons `(id . ,(guix-entry-value entry 'name))
66 entry))
67
68 \f
69 ;;; Hydra jobset 'info'
70
71 (guix-hydra-info-define-interface hydra-jobset
72 :mode-name "Hydra-Jobset-Info"
73 :buffer-name "*Guix Hydra Jobset Info*"
74 :format '((name ignore (simple guix-info-heading))
75 ignore
76 guix-hydra-jobset-info-insert-url
77 (project format guix-hydra-jobset-info-insert-project)
78 (scheduled format (format guix-hydra-jobset-info-scheduled))
79 (succeeded format (format guix-hydra-jobset-info-succeeded))
80 (failed format (format guix-hydra-jobset-info-failed))
81 (total format (format guix-hydra-jobset-info-total))))
82
83 (defface guix-hydra-jobset-info-scheduled
84 '((t))
85 "Face used for the number of scheduled builds."
86 :group 'guix-hydra-jobset-info-faces)
87
88 (defface guix-hydra-jobset-info-succeeded
89 '((t :inherit guix-hydra-build-status-succeeded))
90 "Face used for the number of succeeded builds."
91 :group 'guix-hydra-jobset-info-faces)
92
93 (defface guix-hydra-jobset-info-failed
94 '((t :inherit guix-hydra-build-status-failed))
95 "Face used for the number of failed builds."
96 :group 'guix-hydra-jobset-info-faces)
97
98 (defface guix-hydra-jobset-info-total
99 '((t))
100 "Face used for the total number of builds."
101 :group 'guix-hydra-jobset-info-faces)
102
103 (defun guix-hydra-jobset-info-insert-project (project entry)
104 "Insert PROJECT button for the jobset ENTRY."
105 (let ((jobset (guix-entry-value entry 'name)))
106 (guix-insert-button
107 project 'guix-hydra-build-project
108 'action (lambda (btn)
109 (let ((args (guix-hydra-build-latest-prompt-args
110 :project (button-get btn 'project)
111 :jobset (button-get btn 'jobset))))
112 (apply #'guix-hydra-build-get-display
113 'latest args)))
114 'project project
115 'jobset jobset)))
116
117 (defun guix-hydra-jobset-info-insert-url (entry)
118 "Insert Hydra URL for the jobset ENTRY."
119 (guix-insert-button (guix-hydra-jobset-url
120 (guix-entry-value entry 'project)
121 (guix-entry-value entry 'name))
122 'guix-url))
123
124 \f
125 ;;; Hydra jobset 'list'
126
127 (guix-hydra-list-define-interface hydra-jobset
128 :mode-name "Hydra-Jobset-List"
129 :buffer-name "*Guix Hydra Jobset List*"
130 :format '((name nil 25 t)
131 (project nil 10 t)
132 (scheduled nil 12 t)
133 (succeeded nil 12 t)
134 (failed nil 9 t)
135 (total nil 10 t)))
136
137 (let ((map guix-hydra-jobset-list-mode-map))
138 (define-key map (kbd "B") 'guix-hydra-jobset-list-latest-builds))
139
140 (defun guix-hydra-jobset-list-latest-builds (number &rest args)
141 "Display latest NUMBER of Hydra builds of the current jobset.
142 Interactively, prompt for NUMBER. With prefix argument, prompt
143 for all ARGS."
144 (interactive
145 (let ((entry (guix-list-current-entry)))
146 (guix-hydra-build-latest-prompt-args
147 :project (guix-entry-value entry 'project)
148 :jobset (guix-entry-value entry 'name))))
149 (apply #'guix-hydra-latest-builds number args))
150
151 \f
152 ;;; Interactive commands
153
154 ;;;###autoload
155 (defun guix-hydra-jobsets (project)
156 "Display jobsets of PROJECT."
157 (interactive (list (guix-hydra-read-project)))
158 (guix-hydra-jobset-get-display 'project project))
159
160 (provide 'guix-hydra-jobset)
161
162 ;;; guix-hydra-jobset.el ends here