all messages for Guix-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Arun Isaac <arunisaac@systemreboot.net>
To: "Ludovic Courtès" <ludo@gnu.org>
Cc: 34108@debbugs.gnu.org
Subject: [bug#34108] [PATCH] import: github: Use prereleases when package has no releases.
Date: Mon, 21 Jan 2019 01:47:28 +0530	[thread overview]
Message-ID: <cu75zujw0br.fsf@systemreboot.net> (raw)
In-Reply-To: <87h8e6rmdo.fsf@gnu.org>


[-- Attachment #1.1: Type: text/plain, Size: 425 bytes --]


> 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.


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1.2: 0001-import-github-Use-prereleases-when-package-has-no-re.patch --]
[-- Type: text/x-patch, Size: 1966 bytes --]

From f4347eaf3f4516a40bba563a3ec56a7d6b16b7fb Mon Sep 17 00:00:00 2001
From: Arun Isaac <arunisaac@systemreboot.net>
Date: Thu, 17 Jan 2019 01:34:07 +0530
Subject: [PATCH 1/2] import: github: Use prereleases when package has no
 releases.

* guix/import/github.scm (latest-released-version): Use preleases when package
has no releases.
---
 guix/import/github.scm | 14 ++++++--------
 1 file changed, 6 insertions(+), 8 deletions(-)

diff --git a/guix/import/github.scm b/guix/import/github.scm
index e17ef0b840..c78469dac5 100644
--- a/guix/import/github.scm
+++ b/guix/import/github.scm
@@ -171,6 +171,9 @@ empty list."
   "Return a string of the newest released version name 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 if there is no releases"
+  (define (pre-release? x)
+    (hash-ref x "prerelease"))
+
   (let* ((json (fetch-releases-or-tags url)))
     (if (eq? json #f)
         (if (%github-token)
@@ -181,14 +184,9 @@ 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
-                    (filter
-                     (lambda (x)
-                       ;; example pre-release:
-                       ;; https://github.com/wwood/OrfM/releases/tag/v0.5.1
-                       ;; or an all-prerelease set
-                       ;; https://github.com/powertab/powertabeditor/releases
-                       (not (hash-ref x "prerelease")))
-                     json)))
+                    (match (remove pre-release? json)
+                      (() json) ; keep everything
+                      (releases releases))))
           (match releases
             (()                                   ;empty release list
              #f)
-- 
2.19.2


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1.3: 0002-import-github-Improve-readability.patch --]
[-- Type: text/x-patch, Size: 3895 bytes --]

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


[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 487 bytes --]

  reply	other threads:[~2019-01-20 20:18 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-01-16 20:10 [bug#34108] [PATCH] import: github: Use prereleases when package has no releases Arun Isaac
2019-01-18 15:55 ` Ludovic Courtès
2019-01-20 20:17   ` Arun Isaac [this message]
2019-01-21  9:44     ` Ludovic Courtès
2019-01-21 12:36       ` bug#34108: " Arun Isaac

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=cu75zujw0br.fsf@systemreboot.net \
    --to=arunisaac@systemreboot.net \
    --cc=34108@debbugs.gnu.org \
    --cc=ludo@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/guix.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.