[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
03/08: swh: Add 'lookup-snapshot-branch'.
From: |
guix-commits |
Subject: |
03/08: swh: Add 'lookup-snapshot-branch'. |
Date: |
Mon, 6 Sep 2021 17:36:56 -0400 (EDT) |
civodul pushed a commit to branch master
in repository guix.
commit 153fd217b62a3d57d00f2ce440cf010f5070e886
Author: Ludovic Courtès <ludovic.courtes@inria.fr>
AuthorDate: Mon Sep 6 15:43:04 2021 +0200
swh: Add 'lookup-snapshot-branch'.
* guix/swh.scm (<snapshot>)[id]: New field.
(snapshot-url, lookup-snapshot-branch): New procedures.
---
guix/swh.scm | 29 +++++++++++++++++++++++++++++
1 file changed, 29 insertions(+)
diff --git a/guix/swh.scm b/guix/swh.scm
index 4d0a647..922d781 100644
--- a/guix/swh.scm
+++ b/guix/swh.scm
@@ -56,7 +56,9 @@
visit-snapshot
snapshot?
+ snapshot-id
snapshot-branches
+ lookup-snapshot-branch
branch?
branch-name
@@ -296,6 +298,7 @@ FALSE-IF-404? is true, return #f upon 404 responses."
;;
<https://archive.softwareheritage.org/api/1/snapshot/4334c3ed4bb208604ed780d8687fe523837f1bd1/>
(define-json-mapping <snapshot> make-snapshot snapshot?
json->snapshot
+ (id snapshot-id)
(branches snapshot-branches "branches" json->branches))
;; This is used for the "branches" field of snapshots.
@@ -438,6 +441,32 @@ available."
(call (swh-url (visit-snapshot-url visit))
json->snapshot)))
+(define (snapshot-url snapshot branch-count first-branch)
+ "Return the URL of SNAPSHOT such that it contains information for
+BRANCH-COUNT branches, starting at FIRST-BRANCH."
+ (string-append (swh-url "/api/1/snapshot" (snapshot-id snapshot))
+ "?branches_count=" (number->string branch-count)
+ "&branches_from=" (uri-encode first-branch)))
+
+(define (lookup-snapshot-branch snapshot name)
+ "Look up branch NAME on SNAPSHOT. Return the branch, or return #f if it
+could not be found."
+ (or (find (lambda (branch)
+ (string=? (branch-name branch) name))
+ (snapshot-branches snapshot))
+
+ ;; There's no API entry point to look up a snapshot branch by name.
+ ;; Work around that by using the paginated list of branches provided by
+ ;; the /api/1/snapshot API: ask for one branch, and start pagination at
+ ;; NAME.
+ (let ((snapshot (call (snapshot-url snapshot 1 name)
+ json->snapshot)))
+ (match (snapshot-branches snapshot)
+ ((branch)
+ (and (string=? (branch-name branch) name)
+ branch))
+ (_ #f)))))
+
(define (branch-target branch)
"Return the target of BRANCH, either a <revision> or a <release>."
(match (branch-target-type branch)
- branch master updated (b0ea618 -> 49922ef), guix-commits, 2021/09/06
- 03/08: swh: Add 'lookup-snapshot-branch'.,
guix-commits <=
- 01/08: swh: Export <snapshot> accessors., guix-commits, 2021/09/06
- 02/08: swh: <revisions> accept null 'date' fields., guix-commits, 2021/09/06
- 04/08: gnu: ocaml-markup@0.8.0: Use 'ocaml-ounit', not 'ocaml-ounit2'., guix-commits, 2021/09/06
- 05/08: gnu: ocaml-ppx-optcomp: Update to 0.14.3., guix-commits, 2021/09/06
- 06/08: gnu: ocamlformat: Update to 0.19.0., guix-commits, 2021/09/06
- 08/08: gnu: ocaml-ppxlib: Update to 0.23.0., guix-commits, 2021/09/06
- 07/08: gnu: ocaml-ppx-variants-conv: Patch for building with ocaml-ppxlib., guix-commits, 2021/09/06