ci: Add procedures to access jobs and builds.
authorLudovic Courtès <ludo@gnu.org>
Sat, 3 Jul 2021 17:35:18 +0000 (19:35 +0200)
committerLudovic Courtès <ludo@gnu.org>
Sun, 4 Jul 2021 21:00:36 +0000 (23:00 +0200)
* guix/ci.scm (<job>): New record type.
(evaluation-jobs, build, job-build): New procedures.

guix/ci.scm

index bf35732..dde93bb 100644 (file)
             evaluation-complete?
             evaluation-checkouts
 
+            job?
+            job-build-id
+            job-status
+            job-name
+
             %query-limit
             queued-builds
             latest-builds
             evaluation
+            evaluation-jobs
+            build
+            job-build
             latest-evaluations
             evaluations-for-commit
 
                           (vector->list products)
                           '())))))
 
+(define-json-mapping <job> make-job job?
+  json->job
+  (build-id    job-build-id "build")              ;integer
+  (status      job-status "status"                ;symbol
+               integer->build-status)
+  (name        job-name))                         ;string
+
 (define-json-mapping <checkout> make-checkout checkout?
   json->checkout
   (commit      checkout-commit)                   ;string (SHA1)
@@ -197,6 +212,28 @@ as one of their inputs."
                   (evaluation-checkouts evaluation)))
           (latest-evaluations url limit)))
 
+(define (evaluation-jobs url evaluation-id)
+  "Return the list of jobs of evaluation EVALUATION-ID."
+  (map json->job
+       (vector->list
+        (json->scm (http-fetch
+                    (string-append url "/api/jobs?evaluation="
+                                   (number->string evaluation-id)))))))
+
+(define (build url id)
+  "Look up build ID at URL and return it.  Raise &http-get-error if it is not
+found (404)."
+  (json->build
+   (http-fetch (string-append url "/build/"       ;note: no "/api" here
+                              (number->string id)))))
+
+(define (job-build url job)
+  "Return the build associated with JOB."
+  (build url (job-build-id job)))
+
+;; TODO: job history:
+;; https://ci.guix.gnu.org/api/jobs/history?spec=master&names=coreutils.x86_64-linux&nr=10
+
 (define (find-latest-commit-with-substitutes url)
   "Return the latest commit with available substitutes for the Guix package
 definitions at URL.  Return false if no commit were found."