From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([209.51.188.92]:57007) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hQUXU-0000gi-Lf for guix-patches@gnu.org; Tue, 14 May 2019 06:20:06 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hQUXT-0006W8-1m for guix-patches@gnu.org; Tue, 14 May 2019 06:20:04 -0400 Received: from debbugs.gnu.org ([209.51.188.43]:33933) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hQUXS-0006Sw-BZ for guix-patches@gnu.org; Tue, 14 May 2019 06:20:02 -0400 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1hQUXR-0007x9-Uz for guix-patches@gnu.org; Tue, 14 May 2019 06:20:02 -0400 Subject: [bug#35684] import: github: Sort releases before picking the latest one. Resent-Message-ID: From: Arun Isaac In-Reply-To: <87d0kmsc66.fsf@gnu.org> References: <87mujrs5ut.fsf@gnu.org> <87d0kmsc66.fsf@gnu.org> Date: Tue, 14 May 2019 15:49:08 +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: 35684@debbugs.gnu.org --==-=-= Content-Type: multipart/mixed; boundary="=-=-=" --=-=-= Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable > If you don=E2=80=99t mind, you can make it two patches for clarity (one t= hat > defines =E2=80=98release->version=E2=80=99, and one that adds the call to= =E2=80=98sort=E2=80=99) Sure, pleae find attached. --=-=-= Content-Type: text/x-patch Content-Disposition: inline; filename=0001-import-github-Improve-readability.patch Content-Transfer-Encoding: quoted-printable From=20c96956bc6e944f9691773640e402c15215078943 Mon Sep 17 00:00:00 2001 From: Arun Isaac Date: Tue, 14 May 2019 15:44:46 +0530 Subject: [PATCH 1/2] import: github: Improve readability. * guix/import/github.scm (latest-released-version)[release->version]: Separ= ate out release->version as a new function. =2D-- guix/import/github.scm | 53 +++++++++++++++++++++--------------------- 1 file changed, 27 insertions(+), 26 deletions(-) diff --git a/guix/import/github.scm b/guix/import/github.scm index 4d12339204..5f4d9c7267 100644 =2D-- a/guix/import/github.scm +++ b/guix/import/github.scm @@ -174,6 +174,29 @@ the package e.g. 'bedtools2'. Return #f if there is n= o releases" (define (pre-release? x) (hash-ref x "prerelease")) =20 + (define (release->version 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)))) + (let* ((json (fetch-releases-or-tags url))) (if (eq? json #f) (if (%github-token) @@ -183,32 +206,10 @@ 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 (any =2D (lambda (release) =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 (cond =2D ;; some tags include the name of the package e.g. "fdupes-= 1.51" =2D ;; so remove these =2D ((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 ((string-prefix? "v" tag) =2D (substring tag 1)) =2D ;; Finally, reject tags that don't start with a digit: =2D ;; they may not represent a release. =2D ((and (not (string-null? tag)) =2D (char-set-contains? char-set:digit =2D (string-ref tag 0))) =2D tag) =2D (else #f)))) =2D (match (remove pre-release? json) =2D (() json) ; keep everything =2D (releases releases)))))) + (any release->version + (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.21.0 --=-=-= Content-Type: text/x-patch Content-Disposition: inline; filename=0002-import-github-Sort-releases-before-picking-the-lates.patch Content-Transfer-Encoding: quoted-printable From=208192712f8108d0abcd527ff6b16af073c453b780 Mon Sep 17 00:00:00 2001 From: Arun Isaac Date: Tue, 14 May 2019 15:46:19 +0530 Subject: [PATCH 2/2] import: github: Sort releases before picking the latest one. * guix/import/github.scm (latest-released-version): Sort releases before picking the first one as the latest. =2D-- guix/import/github.scm | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/guix/import/github.scm b/guix/import/github.scm index 5f4d9c7267..cdac70420a 100644 =2D-- a/guix/import/github.scm +++ b/guix/import/github.scm @@ -206,10 +206,13 @@ 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 (any release->version =2D (match (remove pre-release? json) =2D (() json) ; keep everything =2D (releases releases)))))) + (match (sort (filter-map release->version + (match (remove pre-release? json) + (() json) ; keep everything + (releases releases))) + version>?) + ((latest-release . _) latest-release) + (() #f))))) =20 (define (latest-release pkg) "Return an for the latest release of PKG." =2D-=20 2.21.0 --=-=-=-- --==-=-= Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQEzBAEBCAAdFiEEf3MDQ/Lwnzx3v3nTLiXui2GAK7MFAlzalhwACgkQLiXui2GA K7PzBAgAoyQgzvScfXVyu3WxGjqIydu+o3e4bzwrPP7VvZWLMky+km0rYjxqrcyo vAADbQp1jLKOYAiKBFpyHj7p84H9TSv4PY/QMlbRrROgl06SPo64IbN/v8cZCzi4 kq7U0ALlLgj2XapAa1LNoc1stfxR+CTj9QRVdnzXrPBKM58gg8Z0KXPvfQrJBnLh 2i4MMkud9dziXvn3yUGPHvKMKH6k0F1lPJ/iXnXd2zeMnTzVIfPF2CreGg9JXk3i uUbbwtnW9vjBPcawdU4YSGIGrDnIC3nqRjJXKNJk/88wxiMMG+IapkJ1MK5o9v4z CD6IeRzEKc8bWDPi1r8D+HYeilGMdg== =Wc/a -----END PGP SIGNATURE----- --==-=-=--