-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathutils.py
41 lines (35 loc) · 1.36 KB
/
utils.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
from base64 import b64encode
from ado import ADOClient, ADORepoClient
from bitbucket import BitBucketClient, BitBucketRepoClient
from client import VCSClient
from common import RepositoryInfo
from github import GitHubClient, GitHubRepoClient
from gitlab import GitLabClient, GitLabRepoClient
def get_client_for_vcs(vcs: str, url: str, token: str):
if vcs == "github":
return GitHubClient(url, token)
elif vcs == "gitlab":
return GitLabClient(url, token)
elif vcs == "ado":
token = b64encode(f":{token}".encode()).decode()
return ADOClient(url, token)
elif vcs == "bitbucket":
return BitBucketClient(url, token)
else:
raise NotImplementedError(f"Unsupported VCS: {vcs}")
def get_repository_client_from_vcs_client(
vcs_client: VCSClient, repo_info: RepositoryInfo
):
if isinstance(vcs_client, GitHubClient):
repo_client_cls = GitHubRepoClient
elif isinstance(vcs_client, GitLabClient):
repo_client_cls = GitLabRepoClient
elif isinstance(vcs_client, ADOClient):
repo_client_cls = ADORepoClient
elif isinstance(vcs_client, BitBucketClient):
repo_client_cls = BitBucketRepoClient
else:
raise NotImplementedError(f"Unsupported VCS: {type(vcs_client)}")
return repo_client_cls(
repo_info, vcs_client.instance_url, vcs_client.instance_token
)