diff --git a/src/byteb4rb1e/utils/vcs/git.py b/src/byteb4rb1e/utils/vcs/git.py index cd4cd87..7d718b2 100644 --- a/src/byteb4rb1e/utils/vcs/git.py +++ b/src/byteb4rb1e/utils/vcs/git.py @@ -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]