From patchwork Sun Jan 20 20:17:28 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Arun Isaac X-Patchwork-Id: 772 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 F161116A3D; Sun, 20 Jan 2019 20:18:24 +0000 (GMT) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on mira.cbaines.net X-Spam-Level: X-Spam-Status: No, score=-1.1 required=5.0 tests=BAYES_00,RCVD_IN_SORBS_WEB, T_DKIM_INVALID,URIBL_BLOCKED autolearn=no 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 6770416A3A for ; Sun, 20 Jan 2019 20:18:22 +0000 (GMT) Received: from localhost ([127.0.0.1]:43897 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1glJXx-0002M5-MP for patchwork@mira.cbaines.net; Sun, 20 Jan 2019 15:18:21 -0500 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 X-Loop: help-debbugs@gnu.org Subject: [bug#34108] [PATCH] import: github: Use prereleases when package has no releases. Resent-From: Arun Isaac Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Sun, 20 Jan 2019 20:18:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 34108 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: Ludovic =?utf-8?q?Court=C3=A8s?= Received: via spool by 34108-submit@debbugs.gnu.org id=B34108.154801546413597 (code B ref 34108); Sun, 20 Jan 2019 20:18:02 +0000 Received: (at 34108) by debbugs.gnu.org; 20 Jan 2019 20:17:44 +0000 Received: from localhost ([127.0.0.1]:39219 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1glJXM-0003XE-1P for submit@debbugs.gnu.org; Sun, 20 Jan 2019 15:17:44 -0500 Received: from vultr.systemreboot.net ([45.77.148.100]:47994) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1glJXJ-0003X5-1G for 34108@debbugs.gnu.org; Sun, 20 Jan 2019 15:17:41 -0500 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=riOrFaZvHBYedW0TcEgaTmCZ+B6ZTdJ6elFKnNd+uJE=; b=YcawF/3A1VtOVFEEVZRR7P3KW sAlCZavtdzYdKcubcH7XfW3N606A4OnucYkb7cDiCHfZwjLyFIsYlrOt8Fk1evokCjal23qWpMDZf kCoVitjaPRlwlCeVyFWRA5vNzpP+MCM8j/ylkphrskB2E5jQrW8GZcsuMXsXMuNOxueCU=; Received: from [103.5.134.173] (helo=steel) by systemreboot.net with esmtpsa (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.91) (envelope-from ) id 1glJXE-0002TS-4N; Mon, 21 Jan 2019 01:47:37 +0530 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 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: 34108@debbugs.gnu.org Errors-To: guix-patches-bounces+patchwork=mira.cbaines.net@gnu.org Sender: "Guix-patches" X-getmail-retrieved-from-mailbox: Patches > To improve readability, could you define a ‘pre-release?’ 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. From 10dd67dd2980f532cfffc98a4d8042be5ac34f1e 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. --- 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 --- 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")) - (let loop ((releases - (match (remove pre-release? json) - (() json) ; keep everything - (releases releases)))) - (match releases - (() ;empty release list - #f) - ((release . rest) ;one or more releases - (let ((tag (or (hash-ref release "tag_name") ;a "release" - (hash-ref release "name"))) ;a tag - (name-length (string-length package-name))) - ;; some tags include the name of the package e.g. "fdupes-1.51" - ;; so remove these - (if (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 - (if (string-prefix? "v" tag) - (substring tag 1) - - ;; Finally, reject tags that don't start with a digit: - ;; they may not represent a release. - (if (and (not (string-null? tag)) - (char-set-contains? char-set:digit - (string-ref tag 0))) - tag - (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=? (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)))))) (define (latest-release pkg) "Return an for the latest release of PKG." -- 2.19.2