Add support for Gitea and Forgejo in token handling
- Enhanced the `with_token` function to support Gitea and Forgejo URLs by constructing the appropriate authentication format for generic HTTPS. - Updated tests to validate the new functionality, ensuring correct token injection for Gitea URLs while maintaining existing behavior for GitHub and GitLab. - Improved overall robustness of token handling across different platforms.
This commit is contained in:
@@ -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
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user