guix-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

branch master updated: Add a spec parameter to the /api/evaluations rout


From: Mathieu Othacehe
Subject: branch master updated: Add a spec parameter to the /api/evaluations route.
Date: Wed, 26 May 2021 08:39:12 -0400

This is an automated email from the git hooks/post-receive script.

mothacehe pushed a commit to branch master
in repository guix-cuirass.

The following commit(s) were added to refs/heads/master by this push:
     new 9f63675  Add a spec parameter to the /api/evaluations route.
9f63675 is described below

commit 9f63675ad2ebe72c7fcb05932a2dc5bd4dd8268f
Author: Mathieu Othacehe <othacehe@gnu.org>
AuthorDate: Wed May 26 14:37:13 2021 +0200

    Add a spec parameter to the /api/evaluations route.
    
    * src/cuirass/database.scm (db-get-evaluations): Add an optional spec
    parameter an honor it.
    * src/cuirass/http.scm (url-handler): Add an optional spec parameter to the
    /api/evaluations route and pass it to the db-get-evaluations procedure.
    * doc/cuirass.texi (Web API): Document it.
---
 doc/cuirass.texi         |  5 ++++-
 src/cuirass/database.scm | 26 +++++++++++++++++---------
 src/cuirass/http.scm     |  3 ++-
 3 files changed, 23 insertions(+), 11 deletions(-)

diff --git a/doc/cuirass.texi b/doc/cuirass.texi
index 4cf5e88..3735db2 100644
--- a/doc/cuirass.texi
+++ b/doc/cuirass.texi
@@ -739,10 +739,13 @@ The latest evaluations list can be obtained with the API
 evaluations. Evaluations are represented as in the
 "/api/evaluation?id=@var{eval-id}" API.
 
-This request accepts a mandatory parameter.
+This request accepts a mandatory parameter and an optional one.
 @table @code
 @item nr
 Limit query result to nr elements. This parameter is @emph{mandatory}.
+@item spec
+Only consider evaluations that are part of the given @code{spec}
+specification.
 @end table
 
 @subsection Build information
diff --git a/src/cuirass/database.scm b/src/cuirass/database.scm
index 1dffd77..ee866a7 100644
--- a/src/cuirass/database.scm
+++ b/src/cuirass/database.scm
@@ -1392,17 +1392,25 @@ FROM Evaluations WHERE id = " id)
       ((evaluation)
        (parse-evaluation evaluation)))))
 
-(define (db-get-evaluations limit)
+(define* (db-get-evaluations limit
+                             #:optional spec)
   (with-db-worker-thread db
-    (let loop ((rows  (exec-query/bind db "SELECT id, specification, status,
+    (let ((query "SELECT id, specification, status,
 timestamp, checkouttime, evaltime
-FROM Evaluations ORDER BY id DESC LIMIT " limit ";"))
-               (evaluations '()))
-      (match rows
-        (() (reverse evaluations))
-        ((evaluation . rest)
-         (loop rest
-               (cons (parse-evaluation evaluation) evaluations)))))))
+FROM Evaluations
+WHERE specification = :spec OR :spec IS NULL
+ORDER BY id DESC LIMIT :limit;")
+          (params
+           `((#:spec . ,spec)
+             (#:limit . ,limit))))
+      (let loop ((rows
+                  (exec-query/bind-params db query params))
+                 (evaluations '()))
+        (match rows
+          (() (reverse evaluations))
+          ((evaluation . rest)
+           (loop rest
+                 (cons (parse-evaluation evaluation) evaluations))))))))
 
 (define (db-get-evaluations-build-summary spec limit border-low border-high)
   (with-db-worker-thread db
diff --git a/src/cuirass/http.scm b/src/cuirass/http.scm
index 7ab8e47..9232b5d 100644
--- a/src/cuirass/http.scm
+++ b/src/cuirass/http.scm
@@ -816,13 +816,14 @@ passed, only display JOBS targeting this SYSTEM."
            (respond-json-with-error 500 "Parameter not defined!"))))
     (('GET "api" "evaluations")
      (let* ((params (request-parameters request))
+            (spec (assq-ref params 'spec)) ;optional
             ;; 'nr parameter is mandatory to limit query size.
             (nr (assq-ref params 'nr)))
        (if nr
            (respond-json (object->json-string
                           (list->vector
                            (map evaluation->json-object
-                                (db-get-evaluations nr)))))
+                                (db-get-evaluations nr spec)))))
            (respond-json-with-error 500 "Parameter not defined!"))))
     (('GET "api" "latestbuilds")
      (let* ((params (request-parameters request))



reply via email to

[Prev in Thread] Current Thread [Next in Thread]