Subject: [bug#78109] [PATCH Cuirass 2/3] forges: Add %default-forges-channels.

From: Romain GARBAGE <[email-masked]>
Date: Mon, 28 Apr 2025 12:08:47 +0200

* src/cuirass/forges.scm (%default-forges-channels): New variable.
* tests/forges.scm: Add test for %default-forges-channels.
---
 src/cuirass/forges.scm | 17 ++++++++++++++++-
 tests/forges.scm       | 11 ++++++++++-
 2 files changed, 26 insertions(+), 2 deletions(-)

diff --git a/src/cuirass/forges.scm b/src/cuirass/forges.scm
index aeebbec..c5741d5 100644
--- a/src/cuirass/forges.scm
+++ b/src/cuirass/forges.scm
@@ -18,7 +18,9 @@
 
 (define-module (cuirass forges)
   #:use-module ((guix utils) #:select (%current-system))
+  #:use-module (guix channels)
   #:use-module (cuirass config)
+  #:use-module (cuirass parameters)
   #:use-module (cuirass specification)
   #:use-module (cuirass logging)
   #:use-module (json)
@@ -38,7 +40,9 @@
             jobset-options-systems
 
             forge-get-token
-            %forge-token-directory))
+            %forge-token-directory
+
+            %default-forges-channels))
 
 ;;; Commentary:
 ;;;
@@ -143,3 +147,14 @@ both strings. As an exemple, a token for a Git repository located at
              (if (unspecified? v)
                  #f
                  (vector->list v)))))
+
+;; This expands %DEFAULT-CHANNELS to take into account mirror setting.
+(define (%default-forges-channels)
+  (map (lambda (c)
+         (if (and (%guix-mirror-url)
+                  (eq? (channel-name c) 'guix))
+             (channel
+              (inherit c)
+              (url (%guix-mirror-url)))
+             c))
+       %default-channels))
diff --git a/tests/forges.scm b/tests/forges.scm
index 86556da..258addc 100644
--- a/tests/forges.scm
+++ b/tests/forges.scm
@@ -16,7 +16,10 @@
 ;;; You should have received a copy of the GNU General Public License
 ;;; along with Cuirass.  If not, see <http://www.gnu.org/
 
-(use-modules (cuirass forges))
+(use-modules (cuirass forges)
+             (cuirass parameters)
+             (guix channels)
+             (srfi srfi-1))
 
 (parameterize ((%forge-token-directory (mkdtemp "/tmp/cuirass-tokens-XXXXXX")))
   (call-with-output-file (pk 'file (string-append (pk 'tmp (%forge-token-directory))
@@ -35,3 +38,9 @@
   (test-equal "forge-get-token: non-existing server file"
     #f
     (forge-get-token "non-existing" "namespace")))
+
+(parameterize ((%guix-mirror-url "https://codeberg.org/guix/guix-mirror.git"))
+  (test-equal "%default-forges-channels honors %guix-mirror-url"
+    '("https://codeberg.org/guix/guix-mirror.git")
+    (map channel-url
+         (%default-forges-channels))))
-- 
2.49.0