guix-hydra-jobset.el 5.6 KB

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