summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--build-farm-popup.el123
-rw-r--r--build-farm.el10
2 files changed, 130 insertions, 3 deletions
diff --git a/build-farm-popup.el b/build-farm-popup.el
new file mode 100644
index 0000000..7f0bf95
--- /dev/null
+++ b/build-farm-popup.el
@@ -0,0 +1,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
diff --git a/build-farm.el b/build-farm.el
index 969b098..0fe5e2d 100644
--- a/build-farm.el
+++ b/build-farm.el
@@ -6,7 +6,7 @@
;; Version: 0.1
;; URL: https://gitlab.com/alezost-emacs/build-farm
;; Keywords: tools
-;; Package-Requires: ((emacs "24.3") (bui "1.1.0"))
+;; Package-Requires: ((emacs "24.3") (bui "1.1.0") (magit-popup "2.1.0"))
;; 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
@@ -33,7 +33,11 @@
;; Set `build-farm-url' variable to choose what build farm you wish to
;; use.
-;; The following M-x commands display builds, jobsets and projects:
+;; The entry point for the available features is "M-x build-farm". It
+;; provides a Magit-like interface for the commands to display builds,
+;; jobsets and projects.
+
+;; Alternatively, you can use the following M-x commands directly:
;;
;; - `build-farm-latest-builds'
;; - `build-farm-queued-builds'
@@ -41,7 +45,7 @@
;; - `build-farm-jobsets'
;; - `build-farm-projects'
;; - `build-farm-project'
-;;
+
;; You can press RET in a list (of builds, etc.) to see more info on the
;; current entry. You can also select several entries in the list (with
;; "m" key) and press RET to "describe" them.