From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([209.51.188.92]:60382) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1glJXi-0002KG-O7 for guix-patches@gnu.org; Sun, 20 Jan 2019 15:18:10 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1glJXe-0006Yc-Oa for guix-patches@gnu.org; Sun, 20 Jan 2019 15:18:06 -0500 Received: from debbugs.gnu.org ([209.51.188.43]:39938) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1glJXe-0006YW-Kv for guix-patches@gnu.org; Sun, 20 Jan 2019 15:18:02 -0500 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1glJXe-0003Xm-AU for guix-patches@gnu.org; Sun, 20 Jan 2019 15:18:02 -0500 Subject: [bug#34108] [PATCH] import: github: Use prereleases when package has no releases. Resent-Message-ID: From: Arun Isaac In-Reply-To: <87h8e6rmdo.fsf@gnu.org> References: <87h8e6rmdo.fsf@gnu.org> Date: Mon, 21 Jan 2019 01:47:28 +0530 Message-ID: MIME-Version: 1.0 Content-Type: multipart/signed; boundary="==-=-="; micalg=pgp-sha256; protocol="application/pgp-signature" List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guix-patches-bounces+kyle=kyleam.com@gnu.org Sender: "Guix-patches" To: Ludovic =?UTF-8?Q?Court=C3=A8s?= Cc: 34108@debbugs.gnu.org --==-=-= Content-Type: multipart/mixed; boundary="=-=-=" --=-=-= Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable > To improve readability, could you define a =E2=80=98pre-release?=E2=80=99= 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. --=-=-= Content-Type: text/x-patch Content-Disposition: inline; filename=0001-import-github-Use-prereleases-when-package-has-no-re.patch Content-Transfer-Encoding: quoted-printable From=20f4347eaf3f4516a40bba563a3ec56a7d6b16b7fb Mon Sep 17 00:00:00 2001 From: Arun Isaac 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 pack= age has no releases. =2D-- 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 =2D-- 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 se= tting the environment variable GUIX_GITHUB_TOKEN, for instance one procured from https://github.com/settings/tokens")) (let loop ((releases =2D (filter =2D (lambda (x) =2D ;; example pre-release: =2D ;; https://github.com/wwood/OrfM/releases/tag/v0.= 5.1 =2D ;; or an all-prerelease set =2D ;; https://github.com/powertab/powertabeditor/rel= eases =2D (not (hash-ref x "prerelease"))) =2D json))) + (match (remove pre-release? json) + (() json) ; keep everything + (releases releases)))) (match releases (() ;empty release list #f) =2D-=20 2.19.2 --=-=-= Content-Type: text/x-patch Content-Disposition: inline; filename=0002-import-github-Improve-readability.patch Content-Transfer-Encoding: quoted-printable From=2010dd67dd2980f532cfffc98a4d8042be5ac34f1e Mon Sep 17 00:00:00 2001 From: Arun Isaac 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. =2D-- 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 =2D-- 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")) =2D (let loop ((releases =2D (match (remove pre-release? json) =2D (() json) ; keep everything =2D (releases releases)))) =2D (match releases =2D (() ;empty release list =2D #f) =2D ((release . rest) ;one or more releases =2D (let ((tag (or (hash-ref release "tag_name") ;a "release" =2D (hash-ref release "name"))) ;a tag =2D (name-length (string-length package-name))) =2D ;; some tags include the name of the package e.g. "fdupes= -1.51" =2D ;; so remove these =2D (if (and (< name-length (string-length tag)) =2D (string=3D? (string-append package-name "-") =2D (substring tag 0 (+ name-length 1)))) =2D (substring tag (+ name-length 1)) =2D ;; some tags start with a "v" e.g. "v0.25.0" =2D ;; where some are just the version number =2D (if (string-prefix? "v" tag) =2D (substring tag 1) =2D =2D ;; Finally, reject tags that don't start with a d= igit: =2D ;; they may not represent a release. =2D (if (and (not (string-null? tag)) =2D (char-set-contains? char-set:digit =2D (string-ref tag 0))) =2D tag =2D (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=3D? (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)))))) =20 (define (latest-release pkg) "Return an for the latest release of PKG." =2D-=20 2.19.2 --=-=-=-- --==-=-= Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQEzBAEBCAAdFiEEf3MDQ/Lwnzx3v3nTLiXui2GAK7MFAlxE11kACgkQLiXui2GA K7OHlQgAi00T2np2v/6fwNGe0lB4zOPBtPyDIKgvKnUMgcwUmUeMKvB9Wax6TLg3 XDN0LncNpkgHctKXtNSPq7HXPTY3kiqbLsXwvsKuPZpvMdhVrxCIHKbaQVTR/dJ4 5lgLsg9NvX1Fx2yHuZ3osKpMNaBLouKpNb7MtH1UTw3MoYWyU/GbLQhZ2F4huIu5 9kOupt3KlbLBsla75jkjHqIQFFmIDr4hs6EWkhwSd79gBd9h6IrToeOugdaCoyTf UZSTkH83n4nZFjhODelA2OU5yrkmCwAPJFgsi/l6lnYpRYfC0h/eg0fHb8MrWA3q eHloF3BBZJ3oZQ4p/yt0uY916eiICQ== =/7a9 -----END PGP SIGNATURE----- --==-=-=--