diff options
| author | Alex Kost <alezost@gmail.com> | 2018-07-13 20:59:41 +0300 |
|---|---|---|
| committer | Alex Kost <alezost@gmail.com> | 2018-07-16 21:37:19 +0300 |
| commit | 53b540f9ce9a5ada89c8629e9b3742d42219b4de (patch) | |
| tree | 93415b069b3a9eaed5508d04b784722a396c5893 | |
| parent | Add 'build-farm-set-url' command (diff) | |
| download | emacs-build-farm-53b540f9ce9a5ada89c8629e9b3742d42219b4de.tar.gz | |
Move all url procedures to "build-farm-url.el"
* build-farm.el (build-farm-url-alist, build-farm-guess-url)
(build-farm-urls, build-farm-url, build-farm-read-url)
(build-farm-set-url, build-farm-type-by-url, build-farm-api-url)
(build-farm-receive-data): Move to...
* build-farm-build.el (build-farm-build-url, build-farm-build-log-url)
(build-farm-build-latest-api-url, build-farm-build-queue-api-url): Move
to...
* build-farm-jobset.el (build-farm-jobset-url)
(build-farm-jobset-api-url): Move to...
* build-farm-url.el: ... here. New file.
| -rw-r--r-- | build-farm-build.el | 27 | ||||
| -rw-r--r-- | build-farm-jobset.el | 13 | ||||
| -rw-r--r-- | build-farm-url.el | 143 | ||||
| -rw-r--r-- | build-farm.el | 113 |
4 files changed, 158 insertions, 138 deletions
diff --git a/build-farm-build.el b/build-farm-build.el index cde8ec1..322891c 100644 --- a/build-farm-build.el +++ b/build-farm-build.el @@ -26,6 +26,7 @@ (require 'bui) (require 'build-farm) (require 'build-farm-utils) +(require 'build-farm-url) (build-farm-define-entry-type build :search-types '((latest . build-farm-build-latest-api-url) @@ -97,32 +98,6 @@ See `build-farm-search-url' for the meaning of SEARCH-TYPE and ARGS." (guix-build-log-find-file (build-farm-build-log-url id))) -;;; Defining URLs - -(defun build-farm-build-url (id) - "Return URL of a build ID." - (build-farm-url "build/" (number-to-string id))) - -(defun build-farm-build-log-url (id) - "Return URL of the log file of a build ID." - (concat (build-farm-build-url id) "/log/raw")) - -(cl-defun build-farm-build-latest-api-url - (number &key project jobset job system) - "Return API URL to receive latest NUMBER of builds." - (build-farm-api-url "latestbuilds" - `(("nr" . ,number) - ("project" . ,project) - ("jobset" . ,jobset) - ("job" . ,job) - ("system" . ,system)))) - -(defun build-farm-build-queue-api-url (number) - "Return API URL to receive the NUMBER of queued builds." - (build-farm-api-url "queue" - `(("nr" . ,number)))) - - ;;; Filters for processing raw entries (defun build-farm-build-filter-status (entry) diff --git a/build-farm-jobset.el b/build-farm-jobset.el index e5ede38..705c663 100644 --- a/build-farm-jobset.el +++ b/build-farm-jobset.el @@ -26,6 +26,7 @@ (require 'bui) (require 'build-farm) (require 'build-farm-build) +(require 'build-farm-url) (build-farm-define-entry-type jobset :search-types '((project . build-farm-jobset-api-url)) @@ -42,18 +43,6 @@ See `build-farm-search-url' for the meaning of SEARCH-TYPE and ARGS." 'build-farm-jobset search-type args)) -;;; Defining URLs - -(defun build-farm-jobset-url (project jobset) - "Return URL of a PROJECT's JOBSET." - (build-farm-url "jobset/" project "/" jobset)) - -(defun build-farm-jobset-api-url (project) - "Return API URL for jobsets by PROJECT." - (build-farm-api-url "jobsets" - `(("project" . ,project)))) - - ;;; Filters for processing raw entries (defun build-farm-jobset-filter-id (entry) diff --git a/build-farm-url.el b/build-farm-url.el new file mode 100644 index 0000000..99891bc --- /dev/null +++ b/build-farm-url.el @@ -0,0 +1,143 @@ +;;; build-farm-url.el --- Build farm URLs -*- lexical-binding: t -*- + +;; Copyright © 2015–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 the code to determine various URLs of the build +;; farms and to receive data from them. + +;;; Code: + +(require 'json) +(require 'build-farm-utils) + +(defvar build-farm-url-alist + '(("https://hydra.nixos.org" . hydra) + ("https://hydra.gnu.org" . hydra) + ("https://berlin.guixsd.org" . cuirass)) + "Alist of URLs and their types of the available build farms.") + +(defun build-farm-guess-url () + "Return URL of a build farm that a user probably wants to use." + (if (eq 'guix build-farm-preferred-package-manager) + "https://hydra.gnu.org" + "https://hydra.nixos.org")) + +(defun build-farm-urls () + "Return a list of available build farm URLs." + (mapcar #'car build-farm-url-alist)) + +(defcustom build-farm-url (build-farm-guess-url) + "URL of the default build farm." + :type `(choice ,@(mapcar (lambda (url) (list 'const url)) + (build-farm-urls)) + (string :tag "Other URL")) + :group 'build-farm) + +(defun build-farm-read-url () + "Read from minibuffer and return build farm URL." + (completing-read "Build farm URL: " + (build-farm-urls) + nil nil nil nil + build-farm-url)) + +;;;###autoload +(defun build-farm-set-url (url) + "Set `build-farm-url' to URL. +Interactively, prompt for URL" + (interactive (list (build-farm-read-url))) + (setq build-farm-url url)) + +(defun build-farm-type-by-url (url) + "Return build farm type by its URL." + (or (bui-assoc-value build-farm-url-alist url) + (progn + (message "Unknown URL: <%s>. +Consider adding it to `build-farm-url-alist'. +Arbitrarily choosing `hydra' type for this URL." + url) + 'hydra))) + +(defun build-farm-url (&rest url-parts) + "Return build farm URL using URL-PARTS. +URL-PARTS are added to `build-farm-url'." + (apply #'concat build-farm-url "/" url-parts)) + +(defun build-farm-api-url (type args) + "Return URL for receiving data using build farm API. +TYPE is the name of an allowed method. +ARGS is alist of (KEY . VALUE) pairs. +Skip ARG, if VALUE is nil or an empty string." + (declare (indent 1)) + (let* ((fields (mapcar + (lambda (arg) + (pcase arg + (`(,key . ,value) + (unless (or (null value) + (equal "" value)) + (concat (build-farm-hexify key) "=" + (build-farm-hexify value)))) + (_ (error "Wrong argument '%s'" arg)))) + args)) + (fields (mapconcat #'identity (delq nil fields) "&"))) + (build-farm-url "api/" type "?" fields))) + +(defun build-farm-build-url (id) + "Return URL of a build ID." + (build-farm-url "build/" (number-to-string id))) + +(defun build-farm-build-log-url (id) + "Return URL of the log file of a build ID." + (concat (build-farm-build-url id) "/log/raw")) + +(cl-defun build-farm-build-latest-api-url + (number &key project jobset job system) + "Return API URL to receive latest NUMBER of builds." + (build-farm-api-url "latestbuilds" + `(("nr" . ,number) + ("project" . ,project) + ("jobset" . ,jobset) + ("job" . ,job) + ("system" . ,system)))) + +(defun build-farm-build-queue-api-url (number) + "Return API URL to receive the NUMBER of queued builds." + (build-farm-api-url "queue" + `(("nr" . ,number)))) + +(defun build-farm-jobset-url (project jobset) + "Return URL of a PROJECT's JOBSET." + (build-farm-url "jobset/" project "/" jobset)) + +(defun build-farm-jobset-api-url (project) + "Return API URL for jobsets by PROJECT." + (build-farm-api-url "jobsets" + `(("project" . ,project)))) + +(defun build-farm-receive-data (url) + "Return output received from URL and processed with `json-read'." + (with-temp-buffer + (url-insert-file-contents url) + (goto-char (point-min)) + (let ((json-key-type 'symbol) + (json-array-type 'list) + (json-object-type 'alist)) + (json-read)))) + +(provide 'build-farm-url) + +;;; build-farm-url.el ends here diff --git a/build-farm.el b/build-farm.el index 9a28b25..122c9e0 100644 --- a/build-farm.el +++ b/build-farm.el @@ -45,9 +45,9 @@ ;;; Code: -(require 'json) (require 'bui) (require 'build-farm-utils) +(require 'build-farm-url) (defgroup build-farm nil "Interface for Hydra and Cuirass build farms used by Guix and Nix." @@ -71,6 +71,18 @@ "Return job name specification by NAME and VERSION." (concat name "-" version)) +(defun build-farm-get-entries (entry-type search-type &rest args) + "Receive ENTRY-TYPE entries from build farm. +See `build-farm-search-url' for the meaning of SEARCH-TYPE and ARGS." + (unless (eq search-type 'fake) + (let* ((url (apply #'build-farm-search-url + entry-type search-type args)) + (raw-entries (build-farm-receive-data url)) + (entries (apply #'build-farm-modify-objects + raw-entries + (build-farm-filters entry-type)))) + entries))) + (defun build-farm-message (entries search-type &rest _) "Display a message after showing ENTRIES of SEARCH-TYPE." ;; XXX Add more messages maybe. @@ -117,105 +129,6 @@ :single-prompt "System: ") -;;; Defining URLs - -(defvar build-farm-url-alist - '(("https://hydra.nixos.org" . hydra) - ("https://hydra.gnu.org" . hydra) - ("https://berlin.guixsd.org" . cuirass)) - "Alist of URLs and their types of the available build farms.") - -(defun build-farm-guess-url () - "Return URL of a build farm that a user probably wants to use." - (if (eq 'guix build-farm-preferred-package-manager) - "https://hydra.gnu.org" - "https://hydra.nixos.org")) - -(defun build-farm-urls () - "Return a list of available build farm URLs." - (mapcar #'car build-farm-url-alist)) - -(defcustom build-farm-url (build-farm-guess-url) - "URL of the default build farm." - :type `(choice ,@(mapcar (lambda (url) (list 'const url)) - (build-farm-urls)) - (string :tag "Other URL")) - :group 'build-farm) - -(defun build-farm-read-url () - "Read from minibuffer and return build farm URL." - (completing-read "Build farm URL: " - (build-farm-urls) - nil nil nil nil - build-farm-url)) - -;;;###autoload -(defun build-farm-set-url (url) - "Set `build-farm-url' to URL. -Interactively, prompt for URL" - (interactive (list (build-farm-read-url))) - (setq build-farm-url url)) - -(defun build-farm-type-by-url (url) - "Return build farm type by its URL." - (or (bui-assoc-value build-farm-url-alist url) - (progn - (message "Unknown URL: <%s>. -Consider adding it to `build-farm-url-alist'. -Arbitrarily choosing `hydra' type for this URL." - url) - 'hydra))) - -(defun build-farm-url (&rest url-parts) - "Return build farm URL using URL-PARTS. -URL-PARTS are added to `build-farm-url'." - (apply #'concat build-farm-url "/" url-parts)) - -(defun build-farm-api-url (type args) - "Return URL for receiving data using build farm API. -TYPE is the name of an allowed method. -ARGS is alist of (KEY . VALUE) pairs. -Skip ARG, if VALUE is nil or an empty string." - (declare (indent 1)) - (let* ((fields (mapcar - (lambda (arg) - (pcase arg - (`(,key . ,value) - (unless (or (null value) - (equal "" value)) - (concat (build-farm-hexify key) "=" - (build-farm-hexify value)))) - (_ (error "Wrong argument '%s'" arg)))) - args)) - (fields (mapconcat #'identity (delq nil fields) "&"))) - (build-farm-url "api/" type "?" fields))) - - -;;; Receiving data from build farm - -(defun build-farm-receive-data (url) - "Return output received from URL and processed with `json-read'." - (with-temp-buffer - (url-insert-file-contents url) - (goto-char (point-min)) - (let ((json-key-type 'symbol) - (json-array-type 'list) - (json-object-type 'alist)) - (json-read)))) - -(defun build-farm-get-entries (entry-type search-type &rest args) - "Receive ENTRY-TYPE entries from build farm. -See `build-farm-search-url' for the meaning of SEARCH-TYPE and ARGS." - (unless (eq search-type 'fake) - (let* ((url (apply #'build-farm-search-url - entry-type search-type args)) - (raw-entries (build-farm-receive-data url)) - (entries (apply #'build-farm-modify-objects - raw-entries - (build-farm-filters entry-type)))) - entries))) - - ;;; Filters for processing raw entries (defun build-farm-filter-names (entry name-alist) |
