[bug#34108] import: github: Use prereleases when package has no releases.

Message ID cu75zujw0br.fsf@systemreboot.net
State Accepted
Headers show
Series [bug#34108] import: github: Use prereleases when package has no releases. | expand

Checks

Context Check Description
cbaines/applying patch fail Apply failed

Commit Message

Arun Isaac Jan. 20, 2019, 8:17 p.m. UTC
> To improve readability, could you define a ‘pre-release?’ procedure so
> we can write:
>
>   let ((releases (match (remove pre-release? json)
>                    (() json)  ;keep everything
>                    (releases releases))))

I have made this change. In addition, I have also made another patch
improving the readability of the function by using any and cond. Please
find both patches attached.

Comments

Ludovic Courtès Jan. 21, 2019, 9:44 a.m. UTC | #1
Hello!

Arun Isaac <arunisaac@systemreboot.net> skribis:

>> To improve readability, could you define a ‘pre-release?’ procedure so
>> we can write:
>>
>>   let ((releases (match (remove pre-release? json)
>>                    (() json)  ;keep everything
>>                    (releases releases))))
>
> I have made this change. In addition, I have also made another patch
> improving the readability of the function by using any and cond. Please
> find both patches attached.

Both LGTM, thanks for the cleanups!

Ludo’.
Arun Isaac Jan. 21, 2019, 12:36 p.m. UTC | #2
> Both LGTM, thanks for the cleanups!

Pushed, thanks for the review!

Patch

From 10dd67dd2980f532cfffc98a4d8042be5ac34f1e Mon Sep 17 00:00:00 2001
From: Arun Isaac <arunisaac@systemreboot.net>
Date: Mon, 21 Jan 2019 01:43:09 +0530
Subject: [PATCH 2/2] import: github: Improve readability.

* guix/import/github.scm (latest-released-version): Use any and cond instead
of a recursive loop and an if-else ladder respectively.
---
 guix/import/github.scm | 55 ++++++++++++++++++++----------------------
 1 file changed, 26 insertions(+), 29 deletions(-)

diff --git a/guix/import/github.scm b/guix/import/github.scm
index c78469dac5..4d12339204 100644
--- a/guix/import/github.scm
+++ b/guix/import/github.scm
@@ -183,35 +183,32 @@  API when using a GitHub token")
 API. This may be fixed by using an access token and setting the environment
 variable GUIX_GITHUB_TOKEN, for instance one procured from
 https://github.com/settings/tokens"))
-        (let loop ((releases
-                    (match (remove pre-release? json)
-                      (() json) ; keep everything
-                      (releases releases))))
-          (match releases
-            (()                                   ;empty release list
-             #f)
-            ((release . rest)                     ;one or more releases
-             (let ((tag (or (hash-ref release "tag_name") ;a "release"
-                            (hash-ref release "name")))   ;a tag
-                   (name-length (string-length package-name)))
-               ;; some tags include the name of the package e.g. "fdupes-1.51"
-               ;; so remove these
-               (if (and (< name-length (string-length tag))
-                        (string=? (string-append package-name "-")
-                                  (substring tag 0 (+ name-length 1))))
-                   (substring tag (+ name-length 1))
-                   ;; some tags start with a "v" e.g. "v0.25.0"
-                   ;; where some are just the version number
-                   (if (string-prefix? "v" tag)
-                       (substring tag 1)
-
-                       ;; Finally, reject tags that don't start with a digit:
-                       ;; they may not represent a release.
-                       (if (and (not (string-null? tag))
-                                (char-set-contains? char-set:digit
-                                                    (string-ref tag 0)))
-                           tag
-                           (loop rest)))))))))))
+        (any
+         (lambda (release)
+           (let ((tag (or (hash-ref release "tag_name") ;a "release"
+                          (hash-ref release "name")))   ;a tag
+                 (name-length (string-length package-name)))
+             (cond
+              ;; some tags include the name of the package e.g. "fdupes-1.51"
+              ;; so remove these
+              ((and (< name-length (string-length tag))
+                    (string=? (string-append package-name "-")
+                              (substring tag 0 (+ name-length 1))))
+               (substring tag (+ name-length 1)))
+              ;; some tags start with a "v" e.g. "v0.25.0"
+              ;; where some are just the version number
+              ((string-prefix? "v" tag)
+               (substring tag 1))
+              ;; Finally, reject tags that don't start with a digit:
+              ;; they may not represent a release.
+              ((and (not (string-null? tag))
+                    (char-set-contains? char-set:digit
+                                        (string-ref tag 0)))
+               tag)
+              (else #f))))
+         (match (remove pre-release? json)
+           (() json) ; keep everything
+           (releases releases))))))
 
 (define (latest-release pkg)
   "Return an <upstream-source> for the latest release of PKG."
-- 
2.19.2