From e51b808d72de9e0d460ef7ca5ff3ceeb6ee3cb15 Mon Sep 17 00:00:00 2001
From: Antoine Lambert <anlambert@softwareheritage.org>
Date: Wed, 24 Apr 2024 14:25:39 +0200
Subject: [PATCH] nixguix: Ensure to not use a redirection URL as an origin URL

Redirection URLs can be long and quite obscure in some cases (GitHub CDN
for instance) so ensure to use the redirected URL as origin URL.

Related to swh/meta#5090.
---
 swh/lister/nixguix/lister.py            | 4 +---
 swh/lister/nixguix/tests/test_lister.py | 2 +-
 2 files changed, 2 insertions(+), 4 deletions(-)

diff --git a/swh/lister/nixguix/lister.py b/swh/lister/nixguix/lister.py
index 89bf4a84..671e40d4 100644
--- a/swh/lister/nixguix/lister.py
+++ b/swh/lister/nixguix/lister.py
@@ -262,9 +262,7 @@ def is_tarball(
             if location:  # It's not always present
                 logger.debug("Location: %s", location)
                 try:
-                    # FIXME: location is also returned as it's considered the true
-                    # origin, true enough?
-                    return _is_tarball(location), location
+                    return _is_tarball(location), url
                 except ArtifactWithoutExtension:
                     logger.warning(
                         "Still cannot detect extension through location <%s>...",
diff --git a/swh/lister/nixguix/tests/test_lister.py b/swh/lister/nixguix/tests/test_lister.py
index 180fe4fe..ab976f28 100644
--- a/swh/lister/nixguix/tests/test_lister.py
+++ b/swh/lister/nixguix/tests/test_lister.py
@@ -189,7 +189,7 @@ def test_is_tarball_complex_with_location_result(
     is_tar, origin = is_tarball(urls, requests)
     assert is_tar == expected_result
     if is_tar:
-        assert origin == fallback_url
+        assert origin == url
 
 
 @pytest.mark.parametrize(
-- 
GitLab