From patchwork Mon May 13 08:08:37 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Arun Isaac X-Patchwork-Id: 13977 Return-Path: X-Original-To: patchwork@mira.cbaines.net Delivered-To: patchwork@mira.cbaines.net Received: by mira.cbaines.net (Postfix, from userid 113) id 0509D16FDE; Mon, 13 May 2019 09:16:44 +0100 (BST) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on mira.cbaines.net X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,T_DKIM_INVALID, URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.0 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mira.cbaines.net (Postfix) with ESMTP id 903B616F9C for ; Mon, 13 May 2019 09:16:43 +0100 (BST) Received: from localhost ([127.0.0.1]:52897 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hQ68U-0003Ex-DD for patchwork@mira.cbaines.net; Mon, 13 May 2019 04:16:38 -0400 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 X-Loop: help-debbugs@gnu.org Subject: [bug#35684] import: github: Sort releases before picking the latest one. Resent-From: Arun Isaac Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Mon, 13 May 2019 08:10:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 35684 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: To: Ludovic =?utf-8?q?Court=C3=A8s?= Received: via spool by 35684-submit@debbugs.gnu.org id=B35684.155773495116946 (code B ref 35684); Mon, 13 May 2019 08:10:01 +0000 Received: (at 35684) by debbugs.gnu.org; 13 May 2019 08:09:11 +0000 Received: from localhost ([127.0.0.1]:44000 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1hQ61H-0004PF-1B for submit@debbugs.gnu.org; Mon, 13 May 2019 04:09:11 -0400 Received: from mugam.systemreboot.net ([139.59.75.54]:32982) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1hQ61D-0004Oz-Es for 35684@debbugs.gnu.org; Mon, 13 May 2019 04:09:09 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=systemreboot.net; s=default; h=Content-Type:MIME-Version:Message-ID:Date: References:In-Reply-To:Subject:Cc:To:From:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=7uRSojDp+YMRRA5KE66SS0tb40f23E2REhIV/bjHhps=; b=UgxZ7MFRUM4mhkJSXUZb+plE/ mRUSRdRXb8zop6EHSo6TAglGN+Geofh+GTTbAAsNFiJXEQ3J6118PJg1M5s/32vq+tkmqcJdrdmLo K9IsPK+okMfq7GkEOxE8bpkNJl4nBdnFzEA8gZn4bpLkOEfH5faeKHIp148sY+JlDq1Hk=; Received: from [14.139.128.10] (helo=steel) by systemreboot.net with esmtpsa (TLSv1.3:TLS_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1hQ61A-0001A2-9C; Mon, 13 May 2019 13:39:04 +0530 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 X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.51.188.43 X-BeenThere: guix-patches@gnu.org List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: 35684@debbugs.gnu.org Errors-To: guix-patches-bounces+patchwork=mira.cbaines.net@gnu.org Sender: "Guix-patches" X-getmail-retrieved-from-mailbox: Patches > Namely, I think this big ‘lambda’ could be given a name and moved out of > the way to make ‘latest-released-version’ easier to read. Also, it > would probably be reasonable to avoid ‘first’ and instead write: > > (match (sort …) > ((first . _) first) > (() > (leave (G_ "no releases found etc.~%")))) > > WDYT? :-) > > If you’d rather leave that for later, you can also just go ahead and > commit your patch. No problem! :-) Here is the updated patch. From d3f28de8fedc41732a07edf2ea91222208ccc73f 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. --- 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 --- a/guix/import/github.scm +++ b/guix/import/github.scm @@ -174,6 +174,29 @@ the package e.g. 'bedtools2'. Return #f if there is no releases" (define (pre-release? x) (hash-ref x "prerelease")) + (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=? (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")) - (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)))))) + (match (sort (filter-map release->version + (match (remove pre-release? json) + (() json) ; keep everything + (releases releases))) + version>?) + ((latest-release . _) latest-release) + (() #f))))) (define (latest-release pkg) "Return an for the latest release of PKG." -- 2.21.0