fix: read gitlab subgroup repositories whole

This commit is contained in:
Abdessamad Derraz committed 2026-10-17 15:37:23 +02:00
1 parent b023a9fd53
commit 7fd82d452f
2 files changed
+20 -2

No files matched your search

+8 -2
View File
@@ -138,12 +138,18 @@ def parse_repo(url: str) -> Repo | None:
if entry is None:
return None
segments = [s for s in parts.path.split("/") if s]
family, api_base, raw_base = entry
if family == "gitlab" and "-" in segments:
# GitLab nests projects in subgroups; "/-/" opens the project's pages.
segments = segments[: segments.index("-")]
if len(segments) < 2:
return None
owner, name = segments[0], segments[1]
if family == "gitlab":
owner, name = "/".join(segments[:-1]), segments[-1]
else:
owner, name = segments[0], segments[1]
if name.endswith(".git"):
name = name[:-4]
family, api_base, raw_base = entry
return Repo(parts.netloc, family, api_base, raw_base, owner, name)
+12
View File
@@ -54,6 +54,18 @@ class TestParseRepo(unittest.TestCase):
repo = parse_repo("https://gitlab.com/recalbox/recalbox")
self.assertEqual(repo.family, "gitlab")
def test_gitlab_subgroup_keeps_the_whole_namespace(self):
repo = parse_repo(
"https://gitlab.com/recalbox/packages/standalone/rb5000/-/tree/main"
)
self.assertEqual(repo.owner, "recalbox/packages/standalone")
self.assertEqual(repo.name, "rb5000")
self.assertEqual(
raw_url(repo, "abc123", "source/Engine.cpp"),
"https://gitlab.com/recalbox/packages/standalone/rb5000"
"/-/raw/abc123/source/Engine.cpp",
)
def test_libretro_gitlab_is_a_gitlab(self):
repo = parse_repo("https://git.libretro.com/libretro/wqxemu.git")
self.assertEqual(repo.family, "gitlab")