55from codegen .git .schemas .repo_config import RepoConfig
66
77
8+ # TODO: move out doesn't belong here
89def url_to_github (url : str , branch : str ) -> str :
910 clone_url = url .
removesuffix (
".git" ).
replace (
"[email protected] :" ,
"github.com/" )
1011 return f"{ clone_url } /blob/{ branch } "
1112
1213
1314def get_clone_url_for_repo_config (repo_config : RepoConfig , github_type : GithubType = GithubType .GithubEnterprise ) -> str :
14- github_url = f"github.com/{ repo_config .full_name } .git"
15- ghe_url = f"github.codegen.app/{ repo_config .full_name } .git"
1615 if github_type is GithubType .GithubEnterprise :
17- return ghe_url
16+ return f"https://github.codegen.app/ { repo_config . full_name } .git"
1817 elif github_type is GithubType .Github :
19- return github_url
18+ return f"https://github.com/ { repo_config . full_name } .git"
2019
2120
2221def get_authenticated_clone_url_for_repo_config (
@@ -25,9 +24,11 @@ def get_authenticated_clone_url_for_repo_config(
2524) -> str :
2625 git_url = get_clone_url_for_repo_config (repo , github_type )
2726 token = get_token_for_repo_config (repo_config = repo , github_type = github_type )
28- return f"https://x-access-token: { token } @ { git_url } "
27+ return add_access_token_to_url ( git_url , token )
2928
3029
31- def add_token_to_clone_url (clone_url : str , token : str ) -> str :
32- parsed_clone_url = urlparse (clone_url )
33- return f"{ parsed_clone_url .scheme } ://x-access-token:{ token } @{ parsed_clone_url .netloc } { parsed_clone_url .path } "
30+ def add_access_token_to_url (url : str , token : str | None ) -> str :
31+ parsed_url = urlparse (url )
32+ scheme = parsed_url .scheme or "https"
33+ token_prefix = f"x-access-token:{ token } @" if token else ""
34+ return f"{ scheme } ://{ token_prefix } { parsed_url .netloc } { parsed_url .path } "
0 commit comments