From b3f2aab8c9152cbe4ddd984f00de2d0349d9b329 Mon Sep 17 00:00:00 2001 From: Christopher Baines Date: Sun, 12 May 2019 09:51:00 +0100 Subject: [PATCH] Add a JSON variant of the revision page --- guix-data-service/web/controller.scm | 37 ++++++++++++++++++++++------ 1 file changed, 30 insertions(+), 7 deletions(-) diff --git a/guix-data-service/web/controller.scm b/guix-data-service/web/controller.scm index 4142a83..5773e91 100644 --- a/guix-data-service/web/controller.scm +++ b/guix-data-service/web/controller.scm @@ -78,6 +78,33 @@ target-commit (commit->revision-id conn target-commit)))) +(define (render-view-revision mime-types + conn + commit-hash) + (let ((packages-count + (count-packages-in-revision conn commit-hash)) + (derivations-counts + (count-packages-derivations-in-revision conn commit-hash))) + (case (most-appropriate-mime-type + '(application/json text/html) + mime-types) + ((application/json) + (render-json + `((packages_count . ,(caar packages-count)) + (derivations_counts . ,(list->vector + (map (match-lambda + ((system target derivation_count) + `((system . ,system) + (target . ,target) + (derivation_count . ,derivation_count)))) + derivations-counts)))))) + (else + (apply render-html + (view-revision + commit-hash + packages-count + derivations-counts)))))) + (define (render-compare-unknown-commit mime-types conn base-commit @@ -347,13 +374,9 @@ (apply render-html (view-statistics (count-guix-revisions conn) (count-derivations conn)))) - ((GET "revision" commit-hash) - (apply render-html - (view-revision commit-hash - (count-packages-in-revision conn - commit-hash) - (count-packages-derivations-in-revision conn - commit-hash)))) + ((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