diff mbox series

[bug#57460,09/20] refresh: Allow updating to a specific version (github)

Message ID bbee73e7e792cfc217ea6d7d7583ac81b1b0a541.1661691694.git.h.goebel@crazy-compilers.com
State New
Headers show
Series Refresh to specific version | expand

Checks

Context Check Description
cbaines/comparison success View comparision
cbaines/git-branch success View Git branch
cbaines/applying patch success
cbaines/issue success View issue
cbaines/comparison success View comparision
cbaines/git-branch success View Git branch
cbaines/applying patch success View Laminar job
cbaines/issue success View issue

Commit Message

Hartmut Goebel Aug. 28, 2022, 1:18 p.m. UTC
* guix/import/github.scm(latest-released-version): Add keyword-argument
  'version'.  If version is given, try to find the respective release.
  (latest-releease) Rename to (import-release), add keyword-argument 'version'
  and pass it on to latest-released-version.
---
 guix/import/github.scm | 27 +++++++++++++++++----------
 1 file changed, 17 insertions(+), 10 deletions(-)

Comments

Ludovic Courtès Sept. 24, 2022, 9:26 a.m. UTC | #1
Hartmut Goebel <h.goebel@crazy-compilers.com> skribis:

> * guix/import/github.scm(latest-released-version): Add keyword-argument
>   'version'.  If version is given, try to find the respective release.
>   (latest-releease) Rename to (import-release), add keyword-argument 'version'
>   and pass it on to latest-released-version.

(Same comment as before.)

> -     (match (sort (filter-map release->version
> -                              (match (remove pre-release? json)
> -                                (() json)         ; keep everything
> -                                (releases releases)))
> -                  (lambda (x y) (version>? (car x) (car y))))
> +     (let ((releases (filter-map release->version
> +                                 (match (remove pre-release? json)
> +                                        (() json)         ; keep everything
> +                                        (releases releases)))))

Please reindent the ‘match’ form as above.

> +       (match (if version
> +                  ;; find matching release version
> +                  (filter (lambda (x) (string=? version (car x)))
> +                          releases)

Same as earlier: prefer ‘match-lambda’ over ‘car’.

Otherwise LGTM.
diff mbox series

Patch

diff --git a/guix/import/github.scm b/guix/import/github.scm
index ac6ef06eda..facdc96e24 100644
--- a/guix/import/github.scm
+++ b/guix/import/github.scm
@@ -249,7 +249,7 @@  Alternatively, you can wait until your rate limit is reset, or use the
                                            #:headers headers)))
                    (x x)))))))))
 
-(define (latest-released-version url package-name)
+(define* (latest-released-version url package-name #:key (version #f))
   "Return the newest released version and its tag given a string URL like
 'https://github.com/arq5x/bedtools2/archive/v2.24.0.tar.gz' and the name of
 the package e.g. 'bedtools2'.  Return #f (two values) if there are no
@@ -290,15 +290,21 @@  releases."
   (match (and=> (fetch-releases-or-tags url) vector->list)
     (#f (values #f #f))
     (json
-     (match (sort (filter-map release->version
-                              (match (remove pre-release? json)
-                                (() json)         ; keep everything
-                                (releases releases)))
-                  (lambda (x y) (version>? (car x) (car y))))
+     (let ((releases (filter-map release->version
+                                 (match (remove pre-release? json)
+                                        (() json)         ; keep everything
+                                        (releases releases)))))
+       (match (if version
+                  ;; find matching release version
+                  (filter (lambda (x) (string=? version (car x)))
+                          releases)
+                  ;; sort releases descending
+                  (sort releases
+                        (lambda (x y) (version>? (car x) (car y)))))
        (((latest-version . tag) . _) (values latest-version tag))
-       (() (values #f #f))))))
+       (() (values #f #f)))))))
 
-(define (latest-release pkg)
+(define* (import-release pkg #:key (version #f))
   "Return an <upstream-source> for the latest release of PKG."
   (define (github-uri uri)
     (match uri
@@ -313,7 +319,8 @@  releases."
          (source-uri (github-uri original-uri))
          (name (package-name pkg))
          (newest-version version-tag
-                         (latest-released-version source-uri name)))
+                         (latest-released-version source-uri name
+                                                  #:version version)))
     (if newest-version
         (upstream-source
          (package name)
@@ -330,6 +337,6 @@  releases."
    (name 'github)
    (description "Updater for GitHub packages")
    (pred github-package?)
-   (import latest-release)))
+   (import import-release)))