build-farm-project.el 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  1. ;;; build-farm-project.el --- Interface for projects -*- 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 an interface for displaying projects of a build
  17. ;; farm in 'list' and 'info' buffers.
  18. ;;; Code:
  19. (require 'bui)
  20. (require 'build-farm)
  21. (require 'build-farm-url)
  22. (require 'build-farm-build)
  23. (require 'build-farm-jobset)
  24. (build-farm-define-entry-type project
  25. :search-types '((all . build-farm-project-url))
  26. :filter-names '((name . id)
  27. (displayname . name))
  28. ;; Also there is `hidden' boolean field, but it is useless because it
  29. ;; is the same thing as `enabled': when `hidden' is 1, `enabled' is 0,
  30. ;; and vice versa. So `hidden' is not going to be used anywhere.
  31. :filter-boolean-params '(enabled))
  32. ;;; Project 'info'
  33. (build-farm-define-interface project info
  34. :mode-name "Project-Info"
  35. :buffer-name "*Farm Project Info*"
  36. :format '((name nil (simple bui-info-heading))
  37. nil
  38. (description nil (simple build-farm-project-info-description))
  39. nil
  40. build-farm-project-info-insert-url
  41. nil
  42. (id format (format))
  43. (owner format (format build-farm-project-info-owner))
  44. (enabled format build-farm-project-info-insert-enabled)
  45. (releases format (format))
  46. (jobsets simple build-farm-project-info-insert-jobsets)))
  47. (defface build-farm-project-info-description
  48. '((t :inherit font-lock-doc-face))
  49. "Face used for a project description."
  50. :group 'build-farm-project-info-faces)
  51. (defface build-farm-project-info-owner
  52. '((t :inherit font-lock-constant-face))
  53. "Face used for the owner of a project."
  54. :group 'build-farm-project-info-faces)
  55. (defface build-farm-project-info-enabled
  56. '((t :inherit success))
  57. "Face used for enabled projects."
  58. :group 'build-farm-project-info-faces)
  59. (defface build-farm-project-info-disabled
  60. '((t :inherit shadow))
  61. "Face used for disabled projects."
  62. :group 'build-farm-project-info-faces)
  63. (defun build-farm-project-info-insert-url (entry)
  64. "Insert URL for the project ENTRY."
  65. (bui-insert-button (build-farm-project-url
  66. :root-url (build-farm-current-url)
  67. :project (bui-entry-id entry))
  68. 'bui-url)
  69. (bui-newline))
  70. (defun build-farm-project-info-insert-enabled (value _entry)
  71. "Insert boolean VALUE showing whether this project is enabled."
  72. (if value
  73. (bui-info-insert-value-format "Yes" 'build-farm-project-info-enabled)
  74. (bui-info-insert-value-format "No" 'build-farm-project-info-disabled)))
  75. (defun build-farm-project-info-insert-jobsets (jobsets entry)
  76. "Insert JOBSETS of the project ENTRY."
  77. (let ((project (bui-entry-id entry)))
  78. (when (cdr jobsets)
  79. (bui-insert-indent)
  80. (bui-insert-action-button
  81. "List"
  82. (lambda (btn)
  83. (build-farm-get-display
  84. (build-farm-current-url) 'hydra-jobset
  85. 'project (button-get btn 'project)))
  86. "Show jobsets in a 'list' buffer"
  87. 'project project))
  88. (dolist (jobset jobsets)
  89. (bui-newline)
  90. (bui-insert-indent)
  91. (build-farm-project-info-insert-jobset project jobset))))
  92. (defun build-farm-project-info-insert-jobset (project jobset)
  93. "Insert info about JOBSET of the PROJECT at point."
  94. (build-farm-info-insert-hydra-jobset project jobset)
  95. (bui-insert-indent)
  96. (build-farm-info-insert-builds-button
  97. :project project
  98. :jobset jobset))
  99. ;;; Project 'list'
  100. (build-farm-define-interface project list
  101. :describe-function 'build-farm-list-describe
  102. :mode-name "Project-List"
  103. :buffer-name "*Farm Projects*"
  104. :format '((name build-farm-project-list-get-name 25 t)
  105. (owner nil 22 t)
  106. (description bui-list-get-one-line 30 t))
  107. :hint 'build-farm-project-list-hint)
  108. (let ((map build-farm-project-list-mode-map))
  109. (define-key map (kbd "B") 'build-farm-project-list-latest-builds)
  110. (define-key map (kbd "J") 'build-farm-project-list-jobsets))
  111. (defface build-farm-project-list-disabled
  112. '((t :inherit build-farm-project-info-disabled))
  113. "Face used for disabled projects."
  114. :group 'build-farm-project-list-faces)
  115. (defvar build-farm-project-list-default-hint
  116. '(("\\[build-farm-project-list-jobsets]")
  117. " show jobsets of the current project;\n"
  118. ("\\[build-farm-project-list-latest-builds]")
  119. " show latest builds of the current project;\n"))
  120. (defun build-farm-project-list-hint ()
  121. "Return hint string for a project-list buffer."
  122. (bui-format-hints
  123. build-farm-project-list-default-hint
  124. (bui-default-hint)))
  125. (defun build-farm-project-list-read-jobset ()
  126. "Read jobset for the current project."
  127. (build-farm-completing-read
  128. "Jobset: "
  129. (bui-entry-non-void-value (bui-list-current-entry)
  130. 'jobsets)))
  131. (defun build-farm-project-list-get-name (name entry)
  132. "Return NAME of the project ENTRY.
  133. Colorize it with an appropriate face if needed."
  134. (bui-get-string
  135. name
  136. (unless (bui-entry-non-void-value entry 'enabled)
  137. 'build-farm-project-list-disabled)))
  138. (declare-function build-farm-jobsets "build-farm-jobset")
  139. (defun build-farm-project-list-jobsets ()
  140. "Display jobsets of the current project."
  141. (interactive)
  142. (build-farm-get-display (build-farm-current-url)
  143. 'hydra-jobset
  144. 'project (bui-list-current-id)))
  145. (defun build-farm-project-list-latest-builds (number &rest args)
  146. "Display latest NUMBER of builds of the current project.
  147. Interactively, use `build-farm-number-of-builds' variable for
  148. NUMBER. With prefix argument, prompt for it and for the other
  149. ARGS."
  150. (interactive
  151. (build-farm-build-latest-prompt-args
  152. :project (bui-list-current-id)
  153. :jobset (build-farm-project-list-read-jobset)))
  154. (apply #'build-farm-get-display
  155. (build-farm-current-url) 'build 'latest number args))
  156. ;;; Interactive commands
  157. ;;;###autoload
  158. (defun build-farm-projects ()
  159. "Display build farm projects."
  160. (interactive)
  161. (build-farm-check-project-support)
  162. (build-farm-get-display build-farm-url 'project 'all))
  163. ;;;###autoload
  164. (defun build-farm-project (project)
  165. "Display build farm PROJECT."
  166. (interactive (list (build-farm-read-project)))
  167. (build-farm-check-project-support)
  168. (bui-get-display-entries 'build-farm-project 'info
  169. (list build-farm-url 'id project)))
  170. (provide 'build-farm-project)
  171. ;;; build-farm-project.el ends here