build-farm-popup.el 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. ;;; build-farm-popup.el --- Magit-like popup interface -*- lexical-binding: t -*-
  2. ;; Copyright © 2018 Alex Kost <alezost@gmail.com>
  3. ;; This program is free software; you can redistribute it and/or modify
  4. ;; it under the terms of the GNU General Public License as published by
  5. ;; the Free Software Foundation, either version 3 of the License, or
  6. ;; (at your option) any later version.
  7. ;;
  8. ;; This program is distributed in the hope that it will be useful,
  9. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. ;; GNU General Public License for more details.
  12. ;;
  13. ;; You should have received a copy of the GNU General Public License
  14. ;; along with this program. If not, see <http://www.gnu.org/licenses/>.
  15. ;;; Commentary:
  16. ;; This file provides popup interface (using `magit-popup' library) for
  17. ;; build farm commands.
  18. ;;; Code:
  19. (require 'cl-lib)
  20. (require 'magit-popup)
  21. (require 'build-farm-url)
  22. (require 'build-farm-build)
  23. (require 'build-farm-evaluation)
  24. (defgroup build-farm-popup nil
  25. "Variables for popup interface for build farm commands."
  26. :group 'build-farm)
  27. ;;;###autoload (autoload 'build-farm-popup "build-farm-popup" nil t)
  28. (magit-define-popup build-farm-popup
  29. "Show popup buffer for build farm commands."
  30. 'build-farm-popup
  31. :variables '((?u "URL"
  32. build-farm-set-url
  33. build-farm-popup-format-url))
  34. :actions '((?p "projects" build-farm-projects)
  35. (?j "jobsets" build-farm-jobsets)
  36. (?b "builds" build-farm-build-popup)
  37. (?e "evaluations" build-farm-evaluation-popup-maybe)))
  38. ;;;###autoload
  39. (defalias 'build-farm #'build-farm-popup
  40. "Popup interface for the available build farm commands.")
  41. (defun build-farm-popup-variable-value (var-name)
  42. "Return string formatted for popup buffer.
  43. String is made of variable VAR-NAME and its value."
  44. (concat (propertize (symbol-name var-name)
  45. 'face font-lock-variable-name-face)
  46. " "
  47. (propertize (prin1-to-string (symbol-value var-name))
  48. 'face 'magit-popup-option-value)))
  49. (defun build-farm-popup-format-url ()
  50. "Return URL string, formatted for '\\[build-farm]'."
  51. (build-farm-popup-variable-value 'build-farm-url))
  52. (defun build-farm-evaluation-popup-maybe (&optional arg)
  53. "Display popup for evaluations if it is supported.
  54. ARG is passed to `build-farm-evaluation-popup'."
  55. (interactive "P")
  56. (if (eq 'hydra (build-farm-url-type))
  57. (error "Sorry, Hydra evaluations are not supported because of
  58. <https://github.com/NixOS/hydra/issues/582>")
  59. (build-farm-evaluation-popup arg)))
  60. ;;; Builds
  61. (magit-define-popup build-farm-build-popup
  62. "Show popup buffer for builds."
  63. 'build-farm-popup
  64. :variables '("Variable for latest and queued builds"
  65. (?n "number"
  66. build-farm-set-number-of-builds
  67. build-farm-popup-format-number-of-builds))
  68. :options '("Options for latest builds"
  69. (?p "project" "project=" build-farm-popup-read-project)
  70. (?J "jobset" "jobset=" build-farm-popup-read-jobset)
  71. (?j "job" "job=")
  72. (?s "system" "system=" build-farm-read-system))
  73. :actions '((?l "latest" build-farm-popup-latest-builds)
  74. (?q "queued" build-farm-popup-queued-builds)
  75. (?i "build by ID" build-farm-build)))
  76. (defun build-farm-popup-read-project (&optional prompt initial-input)
  77. "Read project from minibuffer.
  78. See `completing-read' for PROMPT and INITIAL-INPUT."
  79. (build-farm-read-project :prompt prompt
  80. :initial-input initial-input))
  81. (defun build-farm-popup-read-jobset (&optional prompt initial-input)
  82. "Read jobset for the current project from minibuffer.
  83. See `completing-read' for PROMPT and INITIAL-INPUT."
  84. (build-farm-read-jobset
  85. :prompt prompt
  86. :initial-input initial-input
  87. :project (plist-get (build-farm-popup-parse-build-args
  88. (magit-popup-get-args))
  89. :project)))
  90. (defun build-farm-popup-format-number-of-builds ()
  91. "Return number of builds, formatted for '\\[build-farm-build-popup]'."
  92. (build-farm-popup-variable-value 'build-farm-number-of-builds))
  93. (defun build-farm-popup-build-args ()
  94. "Return arguments of the current build popup buffer."
  95. (and (eq magit-current-popup 'build-farm-build-popup)
  96. magit-current-popup-args))
  97. (defun build-farm-popup-parse-build-args (args)
  98. "Convert popup ARGS to a form suitable for `build-farm-latest-builds'."
  99. (cl-mapcan (lambda (string)
  100. (cl-multiple-value-bind (key value)
  101. (split-string string "=")
  102. (list (intern (concat ":" key))
  103. value)))
  104. args))
  105. (defun build-farm-popup-latest-builds (&rest args)
  106. "Display `build-farm-number-of-builds' of latest builds.
  107. ARGS are read from the current popup buffer."
  108. (interactive (build-farm-popup-build-args))
  109. (apply #'build-farm-latest-builds
  110. (apply #'build-farm-build-latest-prompt-args
  111. (build-farm-popup-parse-build-args args))))
  112. (defun build-farm-popup-queued-builds ()
  113. "Display `build-farm-number-of-builds' of queued builds."
  114. (interactive)
  115. (build-farm-queued-builds
  116. (or build-farm-number-of-builds
  117. (build-farm-build-read-number))))
  118. ;;; Evaluations
  119. (magit-define-popup build-farm-evaluation-popup
  120. "Show popup buffer for evaluations."
  121. 'build-farm-popup
  122. :variables '((?n "number"
  123. build-farm-set-number-of-evaluations
  124. build-farm-popup-format-number-of-evaluations))
  125. :actions '((?l "latest" build-farm-popup-latest-evaluations)))
  126. (defun build-farm-popup-format-number-of-evaluations ()
  127. "Return number of evaluations for '\\[build-farm-evaluation-popup]'."
  128. (build-farm-popup-variable-value 'build-farm-number-of-evaluations))
  129. (defun build-farm-popup-latest-evaluations ()
  130. "Display `build-farm-number-of-evaluations' of latest evaluations."
  131. (interactive)
  132. (build-farm-latest-evaluations
  133. (or build-farm-number-of-evaluations
  134. (build-farm-evaluation-read-number))))
  135. (provide 'build-farm-popup)
  136. ;;; build-farm-popup.el ends here