summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorLudovic Courtès <ludo@gnu.org>2019-08-17 18:48:34 +0200
committerLudovic Courtès <ludo@gnu.org>2019-08-17 18:48:34 +0200
commitc6f4fa5f577e4752d845fa3ce17c68fcd2079904 (patch)
treec2ab97710592dca9e968ee51a6def3b477087a48 /src
parent92bdf3cda0e366149aa2cb27cd44961f23ea95e6 (diff)
downloadcuirass-c6f4fa5f577e4752d845fa3ce17c68fcd2079904.tar
cuirass-c6f4fa5f577e4752d845fa3ce17c68fcd2079904.tar.gz
Switch to Guile-JSON 3.x.
Guile-JSON 3.x is incompatible with Guile-JSON 1.x, which we relied on until now: it maps JSON dictionaries to alists (instead of hash tables), and JSON arrays to vectors (instead of lists). This commit is about adjusting all the existing code to this new mapping. * src/cuirass/http.scm (evaluation->json-object): New procedure. (handle-builds-request): Pass the result through 'list->vector'. (handle-builds-search-request): Likewise. (url-handler): Likewise for /jobsets, /specifications, /api/evaluations, and /build. For /api/evaluations, use 'evaluation->json-object'. * src/cuirass/utils.scm (object->json-scm): Add 'vector?' case. * tests/http.scm (hash-table-keys, hash-table=?): Remove. (evaluations-query-result): Use vectors for JSON arrays. ("object->json-string"): Expects alists instead of hash tables. ("/build/1"): Use 'lset=' instead of 'hash-table=?'. ("/api/latestbuilds?nr=1&jobset=guix"): Likewise, and expect alists instead of hash tables. ("/api/latestbuilds?nr=1&jobset=gnu"): Likewise. ("/api/evaluations?nr=1"): Likewise. * README: Mention Guile-JSON 3.x.
Diffstat (limited to 'src')
-rw-r--r--src/cuirass/http.scm23
-rw-r--r--src/cuirass/utils.scm4
2 files changed, 21 insertions, 6 deletions
diff --git a/src/cuirass/http.scm b/src/cuirass/http.scm
index b69b6ce..a26b1c6 100644
--- a/src/cuirass/http.scm
+++ b/src/cuirass/http.scm
@@ -105,6 +105,14 @@
(#:releasename . #nil)
(#:buildinputs_builds . #nil)))
+(define (evaluation->json-object evaluation)
+ "Turn EVALUATION into a representation suitable for 'json->scm'."
+ ;; XXX: Since #:checkouts is a list of alists, we must turn it into a vector
+ ;; so that 'json->scm' converts it to a JSON array.
+ `(,@(alist-delete #:checkouts evaluation eq?)
+ (#:checkouts . ,(list->vector
+ (assq-ref evaluation #:checkouts)))))
+
(define (handle-build-request build-id)
"Retrieve build identified by BUILD-ID over the database and convert it to
hydra format. Return #f is not build was found."
@@ -116,14 +124,14 @@ hydra format. Return #f is not build was found."
Hydra format."
(let ((builds (with-time-logging "builds request"
(db-get-builds filters))))
- (map build->hydra-build builds)))
+ (list->vector (map build->hydra-build builds))))
(define (handle-builds-search-request filters)
"Retrieve all builds matched by FILTERS in the database and convert them to
Hydra format."
(let ((builds (with-time-logging "builds search request"
(db-get-builds-by-search filters))))
- (map build->hydra-build builds)))
+ (list->vector (map build->hydra-build builds))))
(define (request-parameters request)
"Parse the REQUEST query parameters and return them under the form
@@ -233,7 +241,8 @@ Hydra format."
(request-path-components request)
'method-not-allowed)
(((or "jobsets" "specifications") . rest)
- (respond-json (object->json-string (db-get-specifications))))
+ (respond-json (object->json-string
+ (list->vector (db-get-specifications)))))
(("build" build-id)
(let ((hydra-build (handle-build-request (string->number build-id))))
(if hydra-build
@@ -274,7 +283,10 @@ Hydra format."
;; 'nr parameter is mandatory to limit query size.
(nr (assq-ref params 'nr)))
(if nr
- (respond-json (object->json-string (db-get-evaluations nr)))
+ (respond-json (object->json-string
+ (list->vector
+ (map evaluation->json-object
+ (db-get-evaluations nr)))))
(respond-json-with-error 500 "Parameter not defined!"))))
(("api" "latestbuilds")
(let* ((params (request-parameters request))
@@ -304,7 +316,8 @@ Hydra format."
('()
(respond-html (html-page
"Cuirass"
- (specifications-table (db-get-specifications))
+ (specifications-table
+ (list->vector (db-get-specifications)))
'())))
(("jobset" name)
diff --git a/src/cuirass/utils.scm b/src/cuirass/utils.scm
index 48e797c..fe74b69 100644
--- a/src/cuirass/utils.scm
+++ b/src/cuirass/utils.scm
@@ -1,5 +1,5 @@
;;; utils.scm -- helper procedures
-;;; Copyright © 2012, 2013, 2016, 2018 Ludovic Courtès <ludo@gnu.org>
+;;; Copyright © 2012, 2013, 2016, 2018, 2019 Ludovic Courtès <ludo@gnu.org>
;;; Copyright © 2015 David Thompson <davet@gnu.org>
;;; Copyright © 2016 Mathieu Lirzin <mthl@gnu.org>
;;; Copyright © 2018 Clément Lassieur <clement@lassieur.org>
@@ -57,6 +57,8 @@
((null? obj) obj)
((symbol? obj) (symbol->string obj))
((keyword? obj) (object->json-scm (keyword->symbol obj)))
+ ((vector? obj) (list->vector
+ (map object->json-scm (vector->list obj))))
((alist? obj) (map object->json-scm obj))
((pair? obj) (cons (object->json-scm (car obj))
(object->json-scm (cdr obj))))