aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristopher Baines <mail@cbaines.net>2019-09-27 17:53:45 +0100
committerChristopher Baines <mail@cbaines.net>2019-09-27 17:53:45 +0100
commit4df889fc3ce99cdb418f1af8f1360cfec77968a7 (patch)
tree39404932ea33c41e4f5659702fdd18c4f092cfd3
parent00ac080297f03b05b13360d96226ea526245bd3e (diff)
downloaddata-service-4df889fc3ce99cdb418f1af8f1360cfec77968a7.tar
data-service-4df889fc3ce99cdb418f1af8f1360cfec77968a7.tar.gz
Add JSON output for the branch package versions page
-rw-r--r--guix-data-service/web/controller.scm41
-rw-r--r--guix-data-service/web/view/html.scm7
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