summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristopher Baines <mail@cbaines.net>2019-05-12 09:51:00 +0100
committerChristopher Baines <mail@cbaines.net>2019-05-12 09:51:28 +0100
commitb3f2aab8c9152cbe4ddd984f00de2d0349d9b329 (patch)
treed7a89e6e54f045dbd0f351de3590df8c5a6a684f
parentbd8b9f951cdcba9eaab6e614ba5f0927176b2600 (diff)
downloaddata-service-b3f2aab8c9152cbe4ddd984f00de2d0349d9b329.tar
data-service-b3f2aab8c9152cbe4ddd984f00de2d0349d9b329.tar.gz
Add a JSON variant of the revision page
-rw-r--r--guix-data-service/web/controller.scm37
1 files 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