1+ from typing import List , Optional , Union
2+
13import logging
4+ import re
25from posixpath import join , normpath
3- from typing import Optional
46
57from gitlab .exceptions import GitlabGetError
68from gitlab .v4 .objects import Project , ProjectManager
1517def submodule_to_project (
1618 submodule : Submodule ,
1719 project_manager : ProjectManager ,
18- self_managed_gitlab_host : Optional [str ] = None ) -> Optional [Project ]:
20+ self_managed_gitlab_host : Optional [Union [str , List [str ]]] = None
21+ ) -> Optional [Project ]:
1922 submodule_project_path_with_namespace = \
2023 _submodule_url_to_path_with_namespace (submodule .url ,
2124 submodule .parent_project ,
@@ -37,7 +40,8 @@ def submodule_to_project(
3740def _submodule_url_to_path_with_namespace (
3841 url : str ,
3942 parent_project : Project ,
40- self_managed_gitlab_host : Optional [str ] = None ) -> Optional [str ]:
43+ self_managed_gitlab_host : Optional [Union [str , List [str ]]] = None
44+ ) -> Optional [str ]:
4145 """Returns a path pointing to a Gitlab project, or None if the submodule
4246 is hosted elsewhere
4347 """
@@ -59,13 +63,17 @@ def _submodule_url_to_path_with_namespace(
5963 # it can still use submodules hosted on gitlab.com
6064 gitlab_hosts = ['gitlab' ]
6165 if self_managed_gitlab_host :
62- gitlab_hosts .append (self_managed_gitlab_host )
66+ if isinstance (self_managed_gitlab_host , str ):
67+ gitlab_hosts .append (self_managed_gitlab_host )
68+ else :
69+ gitlab_hosts .extend (self_managed_gitlab_host )
6370
6471 # giturlparse.GitUrlParsed.platform is too permissive and will be set to
6572 # 'gitlab' for some non-gitlab urls, for instance:
6673 # https://opensource.ncsa.illinois.edu/bitbucket/scm/u3d/3dutilities.git
67- if (parsed .platform != 'gitlab'
68- or all ([host not in parsed .host for host in gitlab_hosts ])):
74+ if (parsed .platform not in ('gitlab' , 'base' )
75+ or not any ([re .match (fr'^{ host } (\.\w+)?$' , parsed .host )
76+ for host in gitlab_hosts ])):
6977 logger .warning (f'submodule git url is not hosted on gitlab: { url } ' )
7078 return None
7179
0 commit comments