aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristopher Baines <mail@cbaines.net>2019-05-12 09:56:24 +0100
committerChristopher Baines <mail@cbaines.net>2019-05-12 09:56:24 +0100
commite64fc090cd6d0bdf2534d8688eec8f3262f4615a (patch)
tree332c8703f9d85a52d535e1420dfe7d0f7c110039
parentb3f2aab8c9152cbe4ddd984f00de2d0349d9b329 (diff)
downloaddata-service-e64fc090cd6d0bdf2534d8688eec8f3262f4615a.tar
data-service-e64fc090cd6d0bdf2534d8688eec8f3262f4615a.tar.gz
Add a JSON variant of the packages page
-rw-r--r--guix-data-service/web/controller.scm29
1 files 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