build-farm-evaluation.el 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. ;;; build-farm-evaluation.el --- Interface for evaluations -*- 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 jobset evaluations of
  17. ;; a build 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. (defgroup build-farm-evaluation nil
  24. "Settings for Hydra and Cuirass evaluations."
  25. :group 'build-farm)
  26. (defcustom build-farm-number-of-evaluations 32
  27. "Default number of latest evaluations to display.
  28. This variable is used by '\\[build-farm-latest-evaluations]'
  29. command. If nil, always prompt for the number of evaluations."
  30. :type 'integer
  31. :group 'build-farm-evaluation)
  32. (defun build-farm-set-number-of-evaluations (number)
  33. "Set `build-farm-number-of-evaluations' to NUMBER."
  34. (interactive (list (build-farm-evaluation-read-number)))
  35. (setq build-farm-number-of-evaluations number))
  36. (defun build-farm-evaluation-read-number (&optional prompt)
  37. "Read from minibuffer (using PROMPT) a number of evaluations."
  38. (read-number (or prompt "Number of evaluations: ")
  39. build-farm-number-of-evaluations))
  40. (defun build-farm-evaluation-info-insert-id (id)
  41. "Insert title for evaluation ID at point."
  42. (bui-format-insert
  43. (concat "Evaluation " (number-to-string id))
  44. 'bui-info-heading))
  45. (defun build-farm-evaluation-info-insert-url (entry)
  46. "Insert URL for the evaluation ENTRY at point."
  47. (bui-insert-button (build-farm-evaluation-url
  48. :root-url (build-farm-current-url)
  49. :evaluation (bui-entry-id entry))
  50. 'bui-url)
  51. (bui-newline))
  52. ;;; Cuirass common
  53. (build-farm-define-entry-type cuirass-evaluation
  54. :search-types '((latest . build-farm-latest-evaluations-api-url))
  55. :filter-names '((specification . jobset))
  56. :filter-boolean-params '(in-progress)
  57. :boolean-params '(in-progress))
  58. ;;; Cuirass Evaluation 'info'
  59. (build-farm-define-interface cuirass-evaluation info
  60. :mode-name "Cuirass-Evaluation-Info"
  61. :buffer-name "*Farm Evaluation Info*"
  62. :format '((id nil (build-farm-evaluation-info-insert-id))
  63. nil
  64. build-farm-evaluation-info-insert-url
  65. nil
  66. (jobset format (build-farm-cuirass-evaluation-info-insert-jobset))
  67. (in-progress format (format))
  68. (checkouts
  69. simple (build-farm-cuirass-evaluation-info-insert-checkouts))))
  70. (bui-define-interface build-farm-cuirass-evaluation-checkouts info
  71. :format '((commit format (format))
  72. (input format (format))
  73. (directory format (format bui-file)))
  74. :reduced? t)
  75. (defun build-farm-cuirass-evaluation-info-insert-jobset (jobset)
  76. "Insert info about Cuirass JOBSET at point."
  77. (build-farm-info-insert-cuirass-jobset jobset)
  78. (bui-insert-indent)
  79. (build-farm-info-insert-builds-button
  80. :jobset jobset))
  81. (defun build-farm-cuirass-evaluation-info-insert-checkouts (checkouts)
  82. "Insert 'cuirass-evaluation' CHECKOUTS at point."
  83. (dolist (checkout checkouts)
  84. (bui-newline)
  85. (bui-info-insert-entry
  86. checkout 'build-farm-cuirass-evaluation-checkouts 1)))
  87. ;;; Cuirass Evaluation 'list'
  88. (build-farm-define-interface cuirass-evaluation list
  89. :describe-function 'build-farm-list-describe
  90. :mode-name "Cuirass-Evaluation-List"
  91. :buffer-name "*Farm Evaluations*"
  92. :format '((id build-farm-cuirass-evaluation-list-id
  93. 10 bui-list-sort-numerically-0)
  94. (jobset nil 30 t)
  95. (commit build-farm-cuirass-evaluation-list-commit 30 t)))
  96. (defface build-farm-cuirass-evaluation-list-in-progress
  97. '((t :inherit font-lock-variable-name-face))
  98. "Face used for evaluation ID if it is in progress."
  99. :group 'build-farm-cuirass-evaluation-list-faces)
  100. (defun build-farm-cuirass-evaluation-list-id (id entry)
  101. "Return first ID of evaluation ENTRY.
  102. Fontify it depending on 'in-progress' status."
  103. (bui-get-string
  104. id
  105. (and (bui-entry-non-void-value entry 'in-progress)
  106. 'build-farm-cuirass-evaluation-list-in-progress)))
  107. (defun build-farm-cuirass-evaluation-list-commit (_ entry)
  108. "Return first commit of evaluation ENTRY."
  109. (let ((checkouts (bui-entry-non-void-value entry 'checkouts)))
  110. (when checkouts
  111. (bui-entry-non-void-value (car checkouts) 'commit))))
  112. ;;; Interactive commands
  113. ;;;###autoload
  114. (defun build-farm-latest-evaluations (number)
  115. "Display latest NUMBER of evaluations.
  116. Interactively, use `build-farm-number-of-builds' variable for
  117. NUMBER. With prefix argument, prompt for it."
  118. (interactive (list (build-farm-evaluation-read-number)))
  119. (if (eq 'hydra (build-farm-url-type))
  120. (error "Hydra API does not support latest evaluations")
  121. (build-farm-get-display build-farm-url
  122. 'cuirass-evaluation 'latest number)))
  123. (provide 'build-farm-evaluation)
  124. ;;; build-farm-evaluation.el ends here