From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([209.51.188.92]:57208) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hPwKD-0000uI-Nm for guix-patches@gnu.org; Sun, 12 May 2019 17:48:06 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hPwKB-0005LD-Sy for guix-patches@gnu.org; Sun, 12 May 2019 17:48:04 -0400 Received: from debbugs.gnu.org ([209.51.188.43]:58244) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hPwKA-0005F1-8B for guix-patches@gnu.org; Sun, 12 May 2019 17:48:02 -0400 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1hPwKA-0007J0-4n for guix-patches@gnu.org; Sun, 12 May 2019 17:48:02 -0400 Subject: [bug#35684] import: github: Sort releases before picking the latest one. Resent-Message-ID: From: Ludovic =?UTF-8?Q?Court=C3=A8s?= References: Date: Sun, 12 May 2019 23:47:06 +0200 In-Reply-To: (Arun Isaac's message of "Sat, 11 May 2019 16:53:21 +0530") Message-ID: <87mujrs5ut.fsf@gnu.org> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable 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: Arun Isaac Cc: 35684@debbugs.gnu.org Arun Isaac skribis: > Prior to this, for some packages (e.g., osc in (gnu packages > build-tools)), `guix refresh' could not find the latest version > correctly. Good catch. > From 33f42ea8a33c6e502062708336a5ab8be871c92b 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 = one. > > * guix/import/github.scm (latest-released-version): Sort releases before > picking the first one as the latest. [...] > + (first > + (sort > + (filter-map > + (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. "fdupe= s-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))) > + version>?))))) LGTM, but=E2=80=A6 =E2=80=A6 while you=E2=80=99re at it, would you mind cleaning this up a bit= ? :-) Namely, I think this big =E2=80=98lambda=E2=80=99 could be given a name and= 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 w= rite: (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. Thanks, Ludo=E2=80=99.