From 64ba3161c90b67926dcfd2592e3b1e562d9cb2ef Mon Sep 17 00:00:00 2001 From: Alex Kost Date: Wed, 18 Jul 2018 22:34:12 +0300 Subject: Use per-buffer build farm URL Previously, a single global 'build-farm-url' variable was used everywhere. But this is not correct: when you change this url, it should take effect only for the future requests, and the existing Farm buffers should use the previous url. So this root url should be local for every build/jobset/project list/info, which is accomplished by this commit. * build-farm-url.el (build-farm-url): Add 'root-url' argument. (build-farm-api-url, build-farm-build-url, build-farm-build-log-url) (build-farm-build-latest-api-url, build-farm-build-queue-api-url) (build-farm-jobset-url, build-farm-jobset-api-url) (build-farm-project-url): Add 'root-url' keyword argument. * build-farm.el: Define accessors for entry args. Specifically... (build-farm-current-url): New function. (build-farm-get-entries, build-farm-get-display, build-farm-message) (build-farm-search-url): New 'root-url' argument. * build-farm-build.el: Adjust to use 'root-url' arguments where appropriate. * build-farm-jobset.el: Likewise. * build-farm-project.el: Likewise. --- build-farm-build.el | 18 ++++++---- build-farm-jobset.el | 6 ++-- build-farm-project.el | 14 +++++--- build-farm-url.el | 95 ++++++++++++++++++++++++++++++--------------------- build-farm.el | 34 ++++++++++++------ 5 files changed, 105 insertions(+), 62 deletions(-) diff --git a/build-farm-build.el b/build-farm-build.el index e919001..58ef7e3 100644 --- a/build-farm-build.el +++ b/build-farm-build.el @@ -86,10 +86,12 @@ for the number of builds." (declare-function guix-build-log-find-file "guix-build-log" (file)) -(defun build-farm-build-view-log (id) +(defun build-farm-build-view-log (id &optional root-url) "View build log of a build ID." (require 'guix-build-log) - (guix-build-log-find-file (build-farm-build-log-url id))) + (guix-build-log-find-file + (build-farm-build-log-url + id :root-url (or root-url (build-farm-current-url))))) ;;; Filters for processing raw entries @@ -263,6 +265,7 @@ See `build-farm-build-status-alist'." :job (button-get btn 'job) :system (button-get btn 'system)))) (apply #'build-farm-get-display + (build-farm-current-url) 'build 'latest args))) (concat "Show latest builds" (let ((thing (cond (job "job") @@ -312,7 +315,9 @@ See `build-farm-build-status-alist'." (defun build-farm-build-info-insert-url (entry) "Insert URL for the build ENTRY." - (bui-insert-button (build-farm-build-url (bui-entry-id entry)) + (bui-insert-button (build-farm-build-url + (bui-entry-id entry) + :root-url (build-farm-current-url)) 'bui-url) (when (build-farm-build-finished? entry) (bui-insert-indent) @@ -374,7 +379,8 @@ ARGS." :jobset (bui-entry-non-void-value entry 'jobset) :job (bui-entry-non-void-value entry 'job) :system (bui-entry-non-void-value entry 'system)))) - (apply #'build-farm-latest-builds number args)) + (apply #'build-farm-get-display + (build-farm-current-url) 'build 'latest number args)) (defun build-farm-build-list-view-log () "View build log of the current build." @@ -393,7 +399,7 @@ NUMBER. With prefix argument, prompt for it and for the other ARGS." (interactive (build-farm-build-latest-prompt-args)) (apply #'build-farm-get-display - 'build 'latest number args)) + build-farm-url 'build 'latest number args)) ;;;###autoload (defun build-farm-queued-builds (number) @@ -406,7 +412,7 @@ NUMBER. With prefix argument, prompt for it." (read-number "Number of queued builds: " build-farm-number-of-builds) build-farm-number-of-builds))) - (build-farm-get-display 'build 'queue number)) + (build-farm-get-display build-farm-url 'build 'queue number)) (provide 'build-farm-build) diff --git a/build-farm-jobset.el b/build-farm-jobset.el index 617a889..c0d1864 100644 --- a/build-farm-jobset.el +++ b/build-farm-jobset.el @@ -97,6 +97,7 @@ (defun build-farm-jobset-info-insert-url (entry) "Insert URL for the jobset ENTRY." (bui-insert-button (build-farm-jobset-url + :root-url (build-farm-current-url) :jobset-id (bui-entry-id entry)) 'bui-url) (bui-newline)) @@ -139,7 +140,8 @@ ARGS." (build-farm-build-latest-prompt-args :project (bui-entry-non-void-value entry 'project) :jobset (bui-entry-non-void-value entry 'name)))) - (apply #'build-farm-latest-builds number args)) + (apply #'build-farm-get-display + (build-farm-current-url) 'build 'latest number args)) ;;; Interactive commands @@ -148,7 +150,7 @@ ARGS." (defun build-farm-jobsets (project) "Display jobsets of PROJECT." (interactive (list (build-farm-read-project))) - (build-farm-get-display 'jobset 'project project)) + (build-farm-get-display build-farm-url 'jobset 'project project)) ;; Info returned for multiple jobsets (from "api/jobsets") and for a ;; single jobset (from "jobset") are completely different! Compare: diff --git a/build-farm-project.el b/build-farm-project.el index 0bd673e..c3cbfe4 100644 --- a/build-farm-project.el +++ b/build-farm-project.el @@ -88,8 +88,10 @@ (defun build-farm-project-info-insert-jobset (project jobset) "Insert info about JOBSET of the PROJECT at point." - (let ((url (build-farm-jobset-url :project project - :jobset jobset))) + (let ((url (build-farm-jobset-url + :root-url (build-farm-current-url) + :project project + :jobset jobset))) (bui-insert-button jobset 'bui-url 'url url 'help-echo (format "Browse %s" url))) @@ -151,7 +153,8 @@ Colorize it with an appropriate face if needed." (defun build-farm-project-list-jobsets () "Display jobsets of the current project." (interactive) - (build-farm-jobsets (bui-list-current-id))) + (build-farm-get-display (build-farm-current-url) + 'jobset 'project (bui-list-current-id))) (defun build-farm-project-list-latest-builds (number &rest args) "Display latest NUMBER of builds of the current project. @@ -162,7 +165,8 @@ ARGS." (build-farm-build-latest-prompt-args :project (bui-list-current-id) :jobset (build-farm-project-list-read-jobset))) - (apply #'build-farm-latest-builds number args)) + (apply #'build-farm-get-display + (build-farm-current-url) 'build 'latest number args)) ;;; Interactive commands @@ -171,7 +175,7 @@ ARGS." (defun build-farm-projects () "Display build farm projects." (interactive) - (build-farm-get-display 'project 'all)) + (build-farm-get-display build-farm-url 'project 'all)) (provide 'build-farm-project) diff --git a/build-farm-url.el b/build-farm-url.el index cc21150..1c566df 100644 --- a/build-farm-url.el +++ b/build-farm-url.el @@ -23,6 +23,7 @@ ;;; Code: (require 'url-handlers) +(require 'url-expand) (require 'json) (require 'build-farm-utils) @@ -76,17 +77,18 @@ Arbitrarily choosing `%S' type for this URL." url type) type))) -(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-url (&optional root-url &rest url-parts) + "Return build farm ROOT-URL with URL-PARTS concatenated to it. +If ROOT-URL is nil, `build-farm-url' variable is used." + (url-expand-file-name (mapconcat #'identity url-parts "") + (or root-url build-farm-url))) -(defun build-farm-api-url (type args) +(cl-defun build-farm-api-url (type args &key root-url) "Return URL for receiving data using build farm API. +See `build-farm-url' for the meaning of ROOT-URL. 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 @@ -98,46 +100,63 @@ Skip ARG, if VALUE is nil or an empty string." (_ (error "Wrong argument '%s'" arg)))) args)) (fields (mapconcat #'identity (delq nil fields) "&"))) - (build-farm-url "api/" type "?" fields))) + (build-farm-url root-url "api/" type "?" fields))) -(defun build-farm-build-url (id) - "Return URL of a build ID." - (build-farm-url "build/" (number-to-string id))) +(cl-defun build-farm-build-url (id &key root-url) + "Return URL of a build ID. +See `build-farm-url' for the meaning of ROOT-URL." + (build-farm-url root-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-log-url (id &key root-url) + "Return URL of the log file of a build ID. +See `build-farm-url' for the meaning of ROOT-URL." + (concat (build-farm-build-url id :root-url root-url) + "/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)))) - -(cl-defun build-farm-jobset-url (&key project jobset jobset-id) + (number &key root-url project jobset job system) + "Return API URL to receive latest NUMBER of builds. +See `build-farm-url' for the meaning of ROOT-URL." + (build-farm-api-url + "latestbuilds" + `(("nr" . ,number) + ("project" . ,project) + ("jobset" . ,jobset) + ("job" . ,job) + ("system" . ,system)) + :root-url root-url)) + +(cl-defun build-farm-build-queue-api-url (number &key root-url) + "Return API URL to receive the NUMBER of queued builds. +See `build-farm-url' for the meaning of ROOT-URL." + (build-farm-api-url + "queue" + `(("nr" . ,number)) + :root-url root-url)) + +(cl-defun build-farm-jobset-url (&key root-url project jobset jobset-id) "Return URL of a PROJECT's JOBSET. -You should specify either a single JOBSET-ID argument (it should have -a form 'project/jobset') or PROJECT and JOBSET arguments." - (build-farm-url "jobset/" +Above that, you should specify either a single JOBSET-ID +argument (it should have a form 'project/jobset') or PROJECT and +JOBSET arguments. +See `build-farm-url' for the meaning of ROOT-URL." + (build-farm-url root-url "/jobset/" (or jobset-id (concat project "/" jobset)))) -(defun build-farm-jobset-api-url (project) - "Return API URL for jobsets by PROJECT." - (build-farm-api-url "jobsets" - `(("project" . ,project)))) - -;; Projects are received from the root build farm page. -(defalias 'build-farm-project-url #'build-farm-url) +(cl-defun build-farm-jobset-api-url (project &key root-url) + "Return API URL for jobsets by PROJECT. +See `build-farm-url' for the meaning of ROOT-URL." + (build-farm-api-url + "jobsets" + `(("project" . ,project)) + :root-url root-url)) + +(cl-defun build-farm-project-url (&key root-url) + "Return URL with bulid farm projects. +See `build-farm-url' for the meaning of ROOT-URL." + ;; Projects are received from the root build farm page. + (build-farm-url root-url)) ;;; Receiving data from a build farm diff --git a/build-farm.el b/build-farm.el index ecaec17..46cb3e0 100644 --- a/build-farm.el +++ b/build-farm.el @@ -96,27 +96,35 @@ If URL is nil, use `build-farm-url'." "Return job name specification by NAME and VERSION." (concat name "-" version)) -(defun build-farm-get-entries (entry-type search-type &rest args) +(bui-define-current-args-accessors build-farm-current + url search-type search-args) + +(defun build-farm-get-entries (root-url 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." +See `build-farm-search-url' for the meaning of ROOT-URL, +SEARCH-TYPE and ARGS." (unless (eq search-type 'fake) (let* ((url (apply #'build-farm-search-url - entry-type search-type args)) + root-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-get-display (entry-type search-type &rest args) +(defun build-farm-get-display (root-url entry-type search-type + &rest args) "Search for ENTRY-TYPE entries and show results. ENTRY-TYPE should be `build', `jobset', etc. -See `build-farm-search-url' for the meaning of SEARCH-TYPE and ARGS." +See `build-farm-search-url' for the meaning of ROOT-URL, +SEARCH-TYPE and ARGS." (apply #'bui-list-get-display-entries (build-farm-symbol entry-type) + root-url search-type args)) -(defun build-farm-message (entries search-type &rest _) +(defun build-farm-message (entries _root-url search-type &rest _) "Display a message after showing ENTRIES of SEARCH-TYPE." ;; XXX Add more messages maybe. (when (null entries) @@ -131,7 +139,7 @@ See `build-farm-search-url' for the meaning of SEARCH-TYPE and ARGS." (bui-current-entry-type) 'info ;; Hydra and Cuirass do not provide an API to receive builds/jobsets ;; by IDs/names, so we use a 'fake' search type. - '(fake) + (list (build-farm-current-url) 'fake) 'add)) @@ -200,14 +208,18 @@ Where '...' is made from SYMBOLS." "Return SYMBOL's value for ENTRY-TYPE." (symbol-value (build-farm-symbol entry-type symbol))) -(defun build-farm-search-url (entry-type search-type &rest args) +(defun build-farm-search-url (root-url entry-type search-type + &rest args) "Return URL to receive ENTRY-TYPE entries from build farm. +ROOT-URL is the url of the build farm (from `build-farm-url-alist'). SEARCH-TYPE is one of the types defined by `build-farm-define-entry-type'. ARGS are passed to the according URL function." (apply (bui-assq-value (build-farm-symbol-value entry-type 'search-types) search-type) - args)) + ;; `:root-url' should be the last argument because `args' may + ;; contain non-keyword arguments. + (append args `(:root-url ,root-url)))) (defun build-farm-filters (entry-type) "Return a list of filters for ENTRY-TYPE." @@ -311,13 +323,13 @@ Run `build-farm-filter-names' with `%S' variable." (setq ,filters-var (cons ',filter-names-fun ,filters-var))))) - (defun ,get-fun (search-type &rest args) + (defun ,get-fun (root-url search-type &rest args) ,(format "\ Receive '%s' entries. See `build-farm-get-entries' for details." entry-type-str) (apply #'build-farm-get-entries - ',entry-type search-type args)) + root-url ',entry-type search-type args)) (bui-define-groups ,full-entry-type :parent-group build-farm -- cgit v1.3