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:
parent
1fd75e11c1
commit
f6283456bb
1 changed files with 16 additions and 30 deletions
|
|
@ -26,54 +26,40 @@ class GitError(Exception):
|
|||
|
||||
|
||||
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
|
||||
requires the Bitbucket API, so other hosts are rejected.
|
||||
Accepts any host (Bitbucket, Forgejo, GitHub, ...) as long as
|
||||
the URL is SCP-style::
|
||||
|
||||
>>> _parse_base_url("git@bitbucket.org:byteb4rb1e")
|
||||
'byteb4rb1e'
|
||||
git@bitbucket.org:byteb4rb1e/foo.git → 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:
|
||||
raise ValueError(
|
||||
f"Expected SCP-style URL (git@bitbucket.org:workspace), "
|
||||
f"Expected SCP-style URL (git@host:workspace), "
|
||||
f"got: {base_url}"
|
||||
)
|
||||
host_part, 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}"
|
||||
)
|
||||
_, workspace = base_url.split(":", 1)
|
||||
return Path(workspace).parent
|
||||
|
||||
|
||||
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
|
||||
requires the Bitbucket API, so other hosts are rejected.
|
||||
Accepts any host (Bitbucket, Forgejo, GitHub, ...) as long as
|
||||
the URL is SCP-style::
|
||||
|
||||
>>> _parse_base_url("git@bitbucket.org:byteb4rb1e")
|
||||
'byteb4rb1e'
|
||||
git@bitbucket.org:byteb4rb1e/foo.git → foo
|
||||
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:
|
||||
raise ValueError(
|
||||
f"Expected SCP-style URL (git@bitbucket.org:workspace), "
|
||||
f"Expected SCP-style URL (git@host:workspace), "
|
||||
f"got: {base_url}"
|
||||
)
|
||||
host_part, 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}"
|
||||
)
|
||||
_, workspace = base_url.split(":", 1)
|
||||
return Path(workspace).name.split('.')[0]
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue