-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathproject_manager_utils.py
More file actions
33 lines (25 loc) · 923 Bytes
/
project_manager_utils.py
File metadata and controls
33 lines (25 loc) · 923 Bytes
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
from typing import Dict, List, Union
from gitlab import Gitlab
from gitlab.v4.objects import ProjectManager
# Some typing
Client = Union[Gitlab, ProjectManager]
OneOrManyClients = Union[Client, List[Client]]
ProjectManagerDicts = Dict[str, ProjectManager]
def as_project_manager(gl: Client) -> ProjectManager:
if isinstance(gl, ProjectManager):
return gl
elif isinstance(gl, Gitlab):
return gl.projects
else:
raise TypeError('Needs a Gitlab instance or its ProjectManager')
def get_host_url(gl: Client) -> str:
if isinstance(gl, Gitlab):
return gl._base_url
elif isinstance(gl, ProjectManager):
return gl.gitlab._base_url
else:
raise TypeError(gl)
def map_domain_to_clients(gls: OneOrManyClients) -> ProjectManagerDicts:
if not isinstance(gls, list):
gls = [gls]
return {get_host_url(gl): as_project_manager(gl) for gl in gls}