blob: 7f0bf95c91ec06ce13042df7e6dfa4d1c7e02928 (
about) (
plain)
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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
|
;;; build-farm-popup.el --- Magit-like popup interface -*- lexical-binding: t -*-
;; Copyright © 2018 Alex Kost <alezost@gmail.com>
;; This program is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.
;;
;; This program is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.
;;
;; You should have received a copy of the GNU General Public License
;; along with this program. If not, see <http://www.gnu.org/licenses/>.
;;; Commentary:
;; This file provides popup interface (using `magit-popup' library) for
;; build farm commands.
;;; Code:
(require 'cl-lib)
(require 'magit-popup)
(require 'build-farm-url)
(require 'build-farm-build)
(defgroup build-farm-popup nil
"Variables for popup interface for build farm commands."
:group 'build-farm)
;;;###autoload (autoload 'build-farm-popup "build-farm-popup" nil t)
(magit-define-popup build-farm-popup
"Show popup buffer for build farm commands."
'build-farm-popup
:variables '((?u "URL"
build-farm-set-url
build-farm-popup-format-url))
:actions '((?p "projects" build-farm-projects)
(?j "jobsets" build-farm-jobsets)
(?b "builds" build-farm-build-popup)))
;;;###autoload
(defalias 'build-farm #'build-farm-popup
"Popup interface for the available build farm commands.")
(magit-define-popup build-farm-build-popup
"Show popup buffer for builds."
'build-farm-popup
:variables '("Variable for latest and queued builds"
(?n "number"
build-farm-set-number-of-builds
build-farm-popup-format-number-of-builds))
:options '(;; "Options for latest and queued builds"
;; (?n "Number of builds" "number="
;; magit-popup-read-number)
"Options for latest builds"
(?p "project" "project=" build-farm-read-project)
(?j "jobset" "jobset=" build-farm-popup-read-jobset)
(?J "job" "job=")
(?s "system" "system=" build-farm-read-system))
:actions '((?l "latest" build-farm-popup-latest-builds)
(?q "queued" build-farm-popup-queued-builds)
(?i "build by ID" build-farm-build)))
(defun build-farm-popup-read-jobset (&optional prompt initial-input)
"Read jobset for the current project from minibuffer.
See `completing-read' for PROMPT and INITIAL-INPUT."
(build-farm-read-jobset
(plist-get (build-farm-popup-parse-build-args
(magit-popup-get-args))
:project)
prompt initial-input))
(defun build-farm-popup-option-value (string &optional description)
"Return STRING formatted for popup buffer.
DESCRIPTION is appended to the resulting string."
(concat description
(propertize (concat "\"" string "\"")
'face 'magit-popup-option-value)))
(defun build-farm-popup-format-url ()
"Return URL string, formatted for '\\[build-farm]'."
(build-farm-popup-option-value build-farm-url "URL "))
(defun build-farm-popup-format-number-of-builds ()
"Return number of builds, formatted for '\\[build-farm-build-popup]'."
(build-farm-popup-option-value
(number-to-string build-farm-number-of-builds)
"Number of builds "))
(defun build-farm-popup-build-args ()
"Return arguments of the current build popup buffer."
(and (eq magit-current-popup 'build-farm-build-popup)
magit-current-popup-args))
(defun build-farm-popup-parse-build-args (args)
"Convert popup ARGS to a form suitable for `build-farm-latest-builds'."
(cl-mapcan (lambda (string)
(cl-multiple-value-bind (key value)
(split-string string "=")
(list (intern (concat ":" key))
value)))
args))
(defun build-farm-popup-latest-builds (&rest args)
"Display `build-farm-number-of-builds' of latest builds.
ARGS are read from the current popup buffer."
(interactive (build-farm-popup-build-args))
(apply #'build-farm-latest-builds
build-farm-number-of-builds
(build-farm-popup-parse-build-args args)))
(defun build-farm-popup-queued-builds ()
"Display `build-farm-number-of-builds' of queued builds."
(interactive)
(build-farm-queued-builds build-farm-number-of-builds))
(provide 'build-farm-popup)
;;; build-farm-popup.el ends here
|