From e64fc090cd6d0bdf2534d8688eec8f3262f4615a Mon Sep 17 00:00:00 2001 From: Christopher Baines Date: Sun, 12 May 2019 09:56:24 +0100 Subject: Add a JSON variant of the packages page --- guix-data-service/web/controller.scm | 29 ++++++++++++++++++++++++----- 1 file changed, 24 insertions(+), 5 deletions(-) diff --git a/guix-data-service/web/controller.scm b/guix-data-service/web/controller.scm index 5773e91..e8381a1 100644 --- a/guix-data-service/web/controller.scm +++ b/guix-data-service/web/controller.scm @@ -105,6 +105,26 @@ packages-count derivations-counts)))))) +(define (render-revision-packages mime-types + conn + commit-hash) + (let ((packages (select-packages-in-revision conn commit-hash))) + (case (most-appropriate-mime-type + '(application/json text/html) + mime-types) + ((application/json) + (render-json + `((packages . ,(list->vector + (map (match-lambda + ((name version synopsis) + `((name . ,name) + (version . ,version) + (synopsis . ,synopsis)))) + packages)))))) + (else + (apply render-html + (view-revision-packages commit-hash packages)))))) + (define (render-compare-unknown-commit mime-types conn base-commit @@ -377,11 +397,10 @@ ((GET "revision" commit-hash) (render-view-revision mime-types conn commit-hash)) - ((GET "revision" commit-hash "packages") - (apply render-html - (view-revision-packages commit-hash - (select-packages-in-revision - conn commit-hash)))) + ((GET "revision" commit-hash "packages") (render-revision-packages + mime-types + conn + commit-hash)) ((GET "revision" commit-hash "package" name version) (apply render-html (view-revision-package-and-version -- cgit v1.2.3