Skip to content

Commit 8dd2471

Browse files
committed
Add support for Gitlab urls in fetch_manifest()
1 parent 110231f commit 8dd2471

File tree

2 files changed

+36
-13
lines changed

2 files changed

+36
-13
lines changed

registry_lib/manifest.py

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
import requests
66

7+
78
if sys.version_info >= (3, 11):
89
import tomllib
910
else:
@@ -16,23 +17,25 @@ def fetch_manifest(git_url, ref="main"):
1617
"""Fetch MANIFEST.toml from git repository.
1718
1819
Args:
19-
git_url: Git repository URL (GitHub only)
20+
git_url: Git repository URL (GitHub or GitLab)
2021
ref: Git ref (branch, tag, or commit)
2122
2223
Returns:
2324
dict: Parsed MANIFEST.toml content
2425
2526
Raises:
26-
ValueError: If URL is not GitHub or manifest is invalid
27+
ValueError: If URL is not GitHub/GitLab or manifest is invalid
2728
requests.HTTPError: If manifest cannot be fetched
2829
"""
29-
if "github.com" not in git_url:
30-
raise ValueError(f"Only GitHub URLs are supported: {git_url}")
31-
32-
# Convert to raw URL
33-
raw_url = git_url.replace("github.com", "raw.githubusercontent.com")
34-
raw_url = raw_url.rstrip("/").removesuffix(".git")
35-
manifest_url = f"{raw_url}/{ref}/MANIFEST.toml"
30+
git_url = git_url.rstrip("/").removesuffix(".git")
31+
32+
if "github.com" in git_url:
33+
raw_url = git_url.replace("github.com", "raw.githubusercontent.com")
34+
manifest_url = f"{raw_url}/{ref}/MANIFEST.toml"
35+
elif "gitlab.com" in git_url:
36+
manifest_url = f"{git_url}/-/raw/{ref}/MANIFEST.toml"
37+
else:
38+
raise ValueError(f"Only GitHub and GitLab URLs are supported: {git_url}")
3639

3740
response = requests.get(manifest_url, timeout=10)
3841
response.raise_for_status()

tests/test_manifest.py

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,30 @@ def test_fetch_manifest_with_git_suffix(mock_get):
4848
assert "plugin/main" in call_url
4949

5050

51-
def test_fetch_manifest_non_github():
52-
"""Test fetch manifest with non-GitHub URL."""
53-
with pytest.raises(ValueError, match="Only GitHub URLs are supported"):
54-
fetch_manifest("https://gitlab.com/user/plugin")
51+
@patch("registry_lib.manifest.requests.get")
52+
def test_fetch_manifest_gitlab(mock_get):
53+
"""Test successful manifest fetch from GitLab."""
54+
mock_response = Mock()
55+
mock_response.text = """
56+
uuid = "12345678-1234-4234-8234-123456789abc"
57+
name = "Test Plugin"
58+
version = "1.0.0"
59+
description = "A test plugin"
60+
api = ["3.0"]
61+
"""
62+
mock_get.return_value = mock_response
63+
64+
manifest = fetch_manifest("https://gitlab.com/user/plugin", "main")
65+
66+
assert manifest["uuid"] == "12345678-1234-4234-8234-123456789abc"
67+
call_url = mock_get.call_args[0][0]
68+
assert "gitlab.com/user/plugin/-/raw/main/MANIFEST.toml" in call_url
69+
70+
71+
def test_fetch_manifest_unsupported():
72+
"""Test fetch manifest with unsupported URL."""
73+
with pytest.raises(ValueError, match="Only GitHub and GitLab URLs are supported"):
74+
fetch_manifest("https://bitbucket.org/user/plugin")
5575

5676

5777
def test_validate_manifest_valid():

0 commit comments

Comments
 (0)