diff --git a/src/gpu_rent/remote/clone_ext.py b/src/gpu_rent/remote/clone_ext.py index 02d7432..a1a7f5a 100644 --- a/src/gpu_rent/remote/clone_ext.py +++ b/src/gpu_rent/remote/clone_ext.py @@ -47,6 +47,16 @@ def with_token(url: str, token: str) -> str: return "https://x-access-token:" + token + "@github.com/" + url[len("https://github.com/") :] if url.startswith("https://gitlab.com/"): return "https://oauth2:" + token + "@gitlab.com/" + url[len("https://gitlab.com/") :] + # Gitea / Forgejo / generic HTTPS — oauth2:TOKEN@host (skip if URL already has userinfo) + if url.startswith("https://"): + parts = urlsplit(url) + if parts.hostname and not parts.username: + netloc = f"oauth2:{token}@{parts.hostname}" + if parts.port: + netloc = f"{netloc}:{parts.port}" + return urlunsplit( + (parts.scheme, netloc, parts.path, parts.query, parts.fragment) + ) return url diff --git a/tests/test_seed.py b/tests/test_seed.py index 8cf49a7..6f6a690 100644 --- a/tests/test_seed.py +++ b/tests/test_seed.py @@ -55,6 +55,10 @@ def test_git_token_injection(): url = "https://github.com/org/Ext.git" assert "x-access-token:secret@" in with_token(url, "secret") assert strip_auth(with_token(url, "secret")) == url + gitea = "https://gitea.hsrv.site/mrleo1nid/swarm-assistent.git" + authed = with_token(gitea, "secret") + assert "oauth2:secret@gitea.hsrv.site" in authed + assert strip_auth(authed) == gitea assert is_sha("a" * 40) assert not is_sha("main")