From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([209.51.188.92]:53621) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hQ68R-0003Dn-RU for guix-patches@gnu.org; Mon, 13 May 2019 04:16:37 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hQ626-0004H2-At for guix-patches@gnu.org; Mon, 13 May 2019 04:10:03 -0400 Received: from debbugs.gnu.org ([209.51.188.43]:58689) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hQ626-0004Gv-76 for guix-patches@gnu.org; Mon, 13 May 2019 04:10:02 -0400 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1hQ625-0004Qu-Rp for guix-patches@gnu.org; Mon, 13 May 2019 04:10:01 -0400 Subject: [bug#35684] import: github: Sort releases before picking the latest one. Resent-Message-ID: From: Arun Isaac In-Reply-To: <87mujrs5ut.fsf@gnu.org> References: <87mujrs5ut.fsf@gnu.org> Date: Mon, 13 May 2019 13:38:37 +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 > Namely, I think this big =E2=80=98lambda=E2=80=99 could be given a name a= nd moved out of > the way to make =E2=80=98latest-released-version=E2=80=99 easier to read.= Also, it > would probably be reasonable to avoid =E2=80=98first=E2=80=99 and instead= write: > > (match (sort =E2=80=A6) > ((first . _) first) > (() > (leave (G_ "no releases found etc.~%")))) > > WDYT? :-) > > If you=E2=80=99d rather leave that for later, you can also just go ahead = and > commit your patch. No problem! :-) Here is the updated patch. --=-=-= Content-Type: text/x-patch Content-Disposition: inline; filename=0001-import-github-Sort-releases-before-picking-the-lates.patch Content-Transfer-Encoding: quoted-printable From=20d3f28de8fedc41732a07edf2ea91222208ccc73f Mon Sep 17 00:00:00 2001 From: Arun Isaac Date: Sat, 11 May 2019 16:40:38 +0530 Subject: [PATCH] import: github: Sort releases before picking the latest on= e. * guix/import/github.scm (latest-released-version): Sort releases before picking the first one as the latest. =2D-- guix/import/github.scm | 56 ++++++++++++++++++++++-------------------- 1 file changed, 30 insertions(+), 26 deletions(-) diff --git a/guix/import/github.scm b/guix/import/github.scm index 4d12339204..cdac70420a 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,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 =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)))))) + (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/Lwnzx3v3nTLiXui2GAK7MFAlzZJgUACgkQLiXui2GA K7O7jQf/eXgA1csQzNoh9vbbaBl+LkHeniV6rinV/90/ml+2/xkYjFOzmLrL4i7y B1KKfFjgNezcL9AWvr1XJSrPRnZV/ERhSkgIAxSaZPRD7BgkmAfYo2kSBu9XWYjO ljMc72/Oqd2cSxfkGJbNf2sAG/LgabLxnSZ8Avfgh6l77LzCYgCoyt0Ytf/N1PU3 k295117JlnGRoyb0O5lJVKNPk0x7dhz87BU7tTowa1O5hMSrNXiPcXhg5ov1Gx41 sb4sW8asgU7JPxprxVlMe1oHZaY3s0sTgLPkRYc6d8rqkdAooz7TWn48Jy6TaUAw Pb0v8GSAXtkVo0LxWs4agGUw5Tw2yg== =6lPO -----END PGP SIGNATURE----- --==-=-=--