From patchwork Fri Dec 21 12:27:03 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Arun Isaac X-Patchwork-Id: 516 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 A99A1169B4; Fri, 21 Dec 2018 12:28:14 +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=-6.9 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_HI, T_DKIM_INVALID,URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.0 Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) by mira.cbaines.net (Postfix) with ESMTP id 32345169B1 for ; Fri, 21 Dec 2018 12:28:14 +0000 (GMT) Received: from localhost ([::1]:45182 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gaJuX-00083D-Nu for patchwork@mira.cbaines.net; Fri, 21 Dec 2018 07:28:13 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:39013) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gaJuS-00081S-35 for guix-patches@gnu.org; Fri, 21 Dec 2018 07:28:08 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gaJuM-0004L3-5V for guix-patches@gnu.org; Fri, 21 Dec 2018 07:28:07 -0500 Received: from debbugs.gnu.org ([208.118.235.43]:52932) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gaJuM-0004Kw-19 for guix-patches@gnu.org; Fri, 21 Dec 2018 07:28:02 -0500 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1gaJuL-0007dD-RN for guix-patches@gnu.org; Fri, 21 Dec 2018 07:28:01 -0500 X-Loop: help-debbugs@gnu.org Subject: [bug#33801] import: github: Support source URIs that redirect to GitHub Resent-From: Arun Isaac Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Fri, 21 Dec 2018 12:28:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 33801 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: To: Ludovic =?utf-8?q?Court=C3=A8s?= Received: via spool by 33801-submit@debbugs.gnu.org id=B33801.154539523629277 (code B ref 33801); Fri, 21 Dec 2018 12:28:01 +0000 Received: (at 33801) by debbugs.gnu.org; 21 Dec 2018 12:27:16 +0000 Received: from localhost ([127.0.0.1]:57190 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1gaJtc-0007c9-CZ for submit@debbugs.gnu.org; Fri, 21 Dec 2018 07:27:16 -0500 Received: from vultr.systemreboot.net ([45.77.148.100]:37060) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1gaJtb-0007c1-5U for 33801@debbugs.gnu.org; Fri, 21 Dec 2018 07:27:15 -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=uWFQDYddJ+0sQKEkN0HJfqOOZQ9y7rUJ6lHTHk2Pjss=; b=pgfXBWFNtqYylcii2a8pNaWpE 9g3h1fWU8hjh+Ce0wureG+Hx9LVNb3I2IMV4aid5HyUQVoUTmnh+fAvU3RNpbeYYqD4sdJ67gFuPM /hqQ51pNRsXmVt7cRSrfBrQnEGPtEXKopZ5exqZLQxNjVxo0q3uTkzsUxwE5LUwcAAZjI=; Received: from [14.139.128.15] (helo=steel) by systemreboot.net with esmtpsa (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.91) (envelope-from ) id 1gaJtW-0007Mk-Pm; Fri, 21 Dec 2018 17:57:11 +0530 From: Arun Isaac In-Reply-To: References: <87d0pxtciz.fsf@gnu.org> <87woo4qxg7.fsf@gnu.org> <87k1k4p3gl.fsf@gnu.org> Date: Fri, 21 Dec 2018 17:57:03 +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: 208.118.235.43 X-BeenThere: guix-patches@gnu.org List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: 33801@debbugs.gnu.org Errors-To: guix-patches-bounces+patchwork=mira.cbaines.net@gnu.org Sender: "Guix-patches" X-getmail-retrieved-from-mailbox: Patches > I will proceed with the lint check as discussed earlier. Please find attached the lint check patch. From 65c540c549c1f2a415b54ccc04dec4b1406bb5eb Mon Sep 17 00:00:00 2001 From: Arun Isaac Date: Fri, 21 Dec 2018 17:48:55 +0530 Subject: [PATCH] guix: lint: Check for source URIs redirecting to GitHub. * guix/scripts/lint.scm (check-github-uri): New procedure. (%checkers): Add it. --- guix/scripts/lint.scm | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/guix/scripts/lint.scm b/guix/scripts/lint.scm index 2314f3b28..4fb2578c9 100644 --- a/guix/scripts/lint.scm +++ b/guix/scripts/lint.scm @@ -8,6 +8,7 @@ ;;; Copyright © 2017 Alex Kost ;;; Copyright © 2017 Tobias Geerinckx-Rice ;;; Copyright © 2017 Efraim Flashner +;;; Copyright © 2018 Arun Isaac ;;; ;;; This file is part of GNU Guix. ;;; @@ -44,8 +45,10 @@ #:use-module (guix cve) #:use-module (gnu packages) #:use-module (ice-9 match) + #:use-module (ice-9 receive) #:use-module (ice-9 regex) #:use-module (ice-9 format) + #:use-module (web client) #:use-module (web uri) #:use-module ((guix build download) #:select (maybe-expand-mirrors @@ -773,6 +776,37 @@ descriptions maintained upstream." (let ((uris (origin-uris origin))) (for-each check-mirror-uri uris))))) +(define (check-github-uri package) + "Check whether PACKAGE uses source URLs that redirect to GitHub." + (define (follow-redirect uri) + (receive (response body) (http-head uri) + (case (response-code response) + ((301 302) + (uri->string (assoc-ref (response-headers response) 'location))) + (else #f)))) + + (define (follow-redirects-to-github uri) + (cond + ((string-prefix? "https://github.com/" uri) uri) + ((string-prefix? "http" uri) + (and=> (follow-redirect uri) follow-redirects-to-github)) + ;; Do not attempt to follow redirects on URIs other than http and https + ;; (such as mirror, file) + (else #f))) + + (let ((origin (package-source package))) + (when (and (origin? origin) + (eqv? (origin-method origin) url-fetch)) + (for-each + (lambda (uri) + (and=> (follow-redirects-to-github uri) + (lambda (github-uri) + (emit-warning + package + (format #f (G_ "URL should be '~a'") github-uri) + 'source)))) + (origin-uris origin))))) + (define (check-derivation package) "Emit a warning if we fail to compile PACKAGE to a derivation." (define (try system) @@ -1055,6 +1089,10 @@ or a list thereof") (name 'mirror-url) (description "Suggest 'mirror://' URLs") (check check-mirror-url)) + (lint-checker + (name 'github-uri) + (description "Suggest GitHub URIs") + (check check-github-uri)) (lint-checker (name 'source-file-name) (description "Validate file names of sources") -- 2.19.2