From 4df889fc3ce99cdb418f1af8f1360cfec77968a7 Mon Sep 17 00:00:00 2001 From: Christopher Baines Date: Fri, 27 Sep 2019 17:53:45 +0100 Subject: Add JSON output for the branch package versions page --- guix-data-service/web/controller.scm | 41 +++++++++++++++++++++++++++--------- guix-data-service/web/view/html.scm | 7 ++++++ 2 files changed, 38 insertions(+), 10 deletions(-) diff --git a/guix-data-service/web/controller.scm b/guix-data-service/web/controller.scm index 77fcc93..0f68969 100644 --- a/guix-data-service/web/controller.scm +++ b/guix-data-service/web/controller.scm @@ -883,16 +883,37 @@ #:before-date (assq-ref parsed-query-parameters 'before_date))))))) (('GET "repository" repository-id "branch" branch-name "package" package-name) - (render-html - #:sxml (view-branch-package - repository-id - branch-name - package-name - (package-versions-for-branch - conn - (string->number repository-id) - branch-name - package-name)))) + (let ((package-versions + (package-versions-for-branch conn + (string->number repository-id) + branch-name + package-name))) + (case (most-appropriate-mime-type + '(application/json text/html) + mime-types) + ((application/json) + (render-json + `((versions . ,(list->vector + (map (match-lambda + ((package-version first-guix-revision-commit + first-datetime + last-guix-revision-commit + last-datetime) + `((version . ,package-version) + (first_revision + . ((commit . ,first-guix-revision-commit) + (datetime . ,first-datetime))) + (last_revision + . ((commit . ,last-guix-revision-commit) + (datetime . ,last-datetime)))))) + package-versions)))))) + (else + (render-html + #:sxml (view-branch-package + repository-id + branch-name + package-name + package-versions)))))) (('GET "repository" repository-id "branch" branch-name "latest-processed-revision") (let ((commit-hash (latest-processed-commit-for-branch conn repository-id branch-name))) diff --git a/guix-data-service/web/view/html.scm b/guix-data-service/web/view/html.scm index a170d6d..e3836ae 100644 --- a/guix-data-service/web/view/html.scm +++ b/guix-data-service/web/view/html.scm @@ -1107,6 +1107,13 @@ (a (@ (href ,(string-append "/repository/" git-repository-id "/branch/" branch-name))) (h3 ,(string-append branch-name " branch"))) + (a (@ (class "btn btn-default btn-lg pull-right") + (href ,(string-append + "/repository/" git-repository-id + "/branch/" branch-name + "/package/" package-name + ".json"))) + "View JSON") (h1 (@ (style "white-space: nowrap;")) (samp ,package-name)))) (div -- cgit v1.2.3