guix-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

07/07: lint: source: Add check for <svn-reference> over HTTP(S).


From: guix-commits
Subject: 07/07: lint: source: Add check for <svn-reference> over HTTP(S).
Date: Mon, 17 Oct 2022 17:18:48 -0400 (EDT)

civodul pushed a commit to branch master
in repository guix.

commit 2383e145185efb2e6f99931707ec93d65d166432
Author: Ludovic Courtès <ludo@gnu.org>
AuthorDate: Mon Oct 17 23:12:07 2022 +0200

    lint: source: Add check for <svn-reference> over HTTP(S).
    
    * guix/lint.scm (svn-reference-uri-with-userinfo): New procedure.
    (check-source): Add 'svn-reference?' clause.
    * tests/lint.scm ("source: svn-reference, HTTP 200")
    ("source: svn-reference, HTTP 404"): New tests.
---
 guix/lint.scm  | 29 +++++++++++++++++++++++++++++
 tests/lint.scm | 32 +++++++++++++++++++++++++++++++-
 2 files changed, 60 insertions(+), 1 deletion(-)

diff --git a/guix/lint.scm b/guix/lint.scm
index 1cbbba75c5..9f155b71d4 100644
--- a/guix/lint.scm
+++ b/guix/lint.scm
@@ -60,6 +60,10 @@
   #:use-module ((guix swh) #:hide (origin?))
   #:autoload   (guix git-download) (git-reference?
                                     git-reference-url git-reference-commit)
+  #:autoload   (guix svn-download) (svn-reference?
+                                    svn-reference-url
+                                    svn-reference-user-name
+                                    svn-reference-password)
   #:use-module (guix import stackage)
   #:use-module (ice-9 match)
   #:use-module (ice-9 regex)
@@ -1138,6 +1142,26 @@ descriptions maintained upstream."
     ((uris ...)
      uris)))
 
+(define (svn-reference-uri-with-userinfo ref)
+  "Return the URI of REF, an <svn-reference> object, but with an additional
+'userinfo' part corresponding to REF's user name and password, provided REF's
+URI is HTTP or HTTPS."
+  (let ((uri (string->uri (svn-reference-url ref))))
+    (if (and (svn-reference-user-name ref)
+             (memq (uri-scheme uri) '(http https)))
+        (build-uri (uri-scheme uri)
+                   #:userinfo
+                   (string-append (svn-reference-user-name ref)
+                                  (if (svn-reference-password ref)
+                                      (string-append
+                                       ":" (svn-reference-password ref))
+                                      ""))
+                   #:host (uri-host uri)
+                   #:port (uri-port uri)
+                   #:query (uri-query uri)
+                   #:fragment (uri-fragment uri))
+        uri)))
+
 (define (check-source package)
   "Emit a warning if PACKAGE has an invalid 'source' field, or if that
 'source' is not reachable."
@@ -1183,6 +1207,11 @@ descriptions maintained upstream."
          ((git-reference? (origin-uri origin))
           (warnings-for-uris
            (list (string->uri (git-reference-url (origin-uri origin))))))
+         ((svn-reference? (origin-uri origin))
+          (let ((uri (svn-reference-uri-with-userinfo (origin-uri origin))))
+            (if (memq (uri-scheme uri) '(http https))
+                (warnings-for-uris (list uri))
+                '())))                            ;TODO: handle svn:// URLs
          (else
           '()))
         '())))
diff --git a/tests/lint.scm b/tests/lint.scm
index 8be74d2604..b848e32aee 100644
--- a/tests/lint.scm
+++ b/tests/lint.scm
@@ -1,7 +1,7 @@
 ;;; GNU Guix --- Functional package management for GNU
 ;;; Copyright © 2012, 2013 Cyril Roelandt <tipecaml@gmail.com>
 ;;; Copyright © 2014, 2015, 2016 Eric Bavier <bavier@member.fsf.org>
-;;; Copyright © 2014, 2015, 2016, 2017, 2018, 2019, 2020, 2021 Ludovic Courtès 
<ludo@gnu.org>
+;;; Copyright © 2014-2022 Ludovic Courtès <ludo@gnu.org>
 ;;; Copyright © 2015, 2016 Mathieu Lirzin <mthl@gnu.org>
 ;;; Copyright © 2016 Hartmut Goebel <h.goebel@crazy-compilers.com>
 ;;; Copyright © 2017 Alex Kost <alezost@gmail.com>
@@ -35,6 +35,7 @@
   #:use-module (guix tests http)
   #:use-module (guix download)
   #:use-module (guix git-download)
+  #:use-module (guix svn-download)
   #:use-module (guix build-system texlive)
   #:use-module (guix build-system emacs)
   #:use-module (guix build-system gnu)
@@ -1085,6 +1086,35 @@
                 (and (? lint-warning?) second-warning))
                (lint-warning-message second-warning)))))))))
 
+(test-equal "source: svn-reference, HTTP 200"
+  '()
+  (with-http-server `((200 ,%long-string))
+    (let ((pkg (package
+                 (inherit (dummy-package "x"))
+                 (source (origin
+                           (method svn-fetch)
+                           (uri (svn-reference
+                                 (url (%local-url))
+                                 (revision 1234)))
+                           (sha256 %null-sha256))))))
+      (check-source pkg))))
+
+(with-http-server `((404 ,%long-string))
+  (test-equal "source: svn-reference, HTTP 404"
+    (format #f "URI ~a not reachable: 404 (\"Such is life\")"
+            (%local-url))
+    (let ((pkg (package
+                 (inherit (dummy-package "x"))
+                 (source (origin
+                           (method svn-fetch)
+                           (uri (svn-reference
+                                 (url (%local-url))
+                                 (revision 1234)))
+                           (sha256 %null-sha256))))))
+      (match (check-source pkg)
+        ((warning)
+         (lint-warning-message warning))))))
+
 (test-equal "mirror-url"
   '()
   (let ((source (origin



reply via email to

[Prev in Thread] Current Thread [Next in Thread]