feat: relax host restriction in vcs.git URL parsing

parse_base_url and parse_repo_name hard-rejected any host other
than bitbucket.org — a leftover from when bootstrapping required
the Bitbucket API. With the Forgejo saas wrapper (#18) in place,
downstream consumers feed Forgejo-shaped URLs through these
helpers. Drop the host check; SCP-style format validation stays.
Also corrects parse_repo_name's docstring, which was a stale
copy of parse_base_url's.
This commit is contained in:
Tiara Rodney 2026-06-06 16:10:16 +02:00
parent 1fd75e11c1
commit f6283456bb
Signed by: tiara
GPG key ID: 5CD8EC1D46106723

View file

@ -26,54 +26,40 @@ class GitError(Exception):
def parse_base_url(base_url: str) -> str: def parse_base_url(base_url: str) -> str:
"""Extract workspace from an SCP-style Bitbucket base URL. """Extract the workspace from an SCP-style base URL.
The host part must be exactly ``bitbucket.org`` bootstrapping Accepts any host (Bitbucket, Forgejo, GitHub, ...) as long as
requires the Bitbucket API, so other hosts are rejected. the URL is SCP-style::
>>> _parse_base_url("git@bitbucket.org:byteb4rb1e") git@bitbucket.org:byteb4rb1e/foo.git byteb4rb1e
'byteb4rb1e' git@git.code.tiararodney.com:h5p-mirror/foo.git h5p-mirror
""" """
# SCP-style: git@bitbucket.org:workspace # SCP-style: git@host:workspace/repo
if ":" not in base_url or "//" in base_url: if ":" not in base_url or "//" in base_url:
raise ValueError( raise ValueError(
f"Expected SCP-style URL (git@bitbucket.org:workspace), " f"Expected SCP-style URL (git@host:workspace), "
f"got: {base_url}" f"got: {base_url}"
) )
host_part, workspace = base_url.split(":", 1) _, workspace = base_url.split(":", 1)
# host_part is e.g. "git@bitbucket.org"
host = host_part.split("@", 1)[-1]
if host != "bitbucket.org":
raise ValueError(
f"Mirror base URL must target bitbucket.org, "
f"got host: {host}"
)
return Path(workspace).parent return Path(workspace).parent
def parse_repo_name(base_url: str) -> str: def parse_repo_name(base_url: str) -> str:
"""Extract workspace from an SCP-style Bitbucket base URL. """Extract the repository name from an SCP-style base URL.
The host part must be exactly ``bitbucket.org`` bootstrapping Accepts any host (Bitbucket, Forgejo, GitHub, ...) as long as
requires the Bitbucket API, so other hosts are rejected. the URL is SCP-style::
>>> _parse_base_url("git@bitbucket.org:byteb4rb1e") git@bitbucket.org:byteb4rb1e/foo.git foo
'byteb4rb1e' git@git.code.tiararodney.com:h5p-mirror/foo.git foo
""" """
# SCP-style: git@bitbucket.org:workspace # SCP-style: git@host:workspace/repo
if ":" not in base_url or "//" in base_url: if ":" not in base_url or "//" in base_url:
raise ValueError( raise ValueError(
f"Expected SCP-style URL (git@bitbucket.org:workspace), " f"Expected SCP-style URL (git@host:workspace), "
f"got: {base_url}" f"got: {base_url}"
) )
host_part, workspace = base_url.split(":", 1) _, workspace = base_url.split(":", 1)
# host_part is e.g. "git@bitbucket.org"
host = host_part.split("@", 1)[-1]
if host != "bitbucket.org":
raise ValueError(
f"Mirror base URL must target bitbucket.org, "
f"got host: {host}"
)
return Path(workspace).name.split('.')[0] return Path(workspace).name.split('.')[0]