From 6772fa76aaa6920ac76b983050efed125280216e Mon Sep 17 00:00:00 2001 From: Jordan Petridis Date: Tue, 23 Oct 2018 22:04:20 +0300 Subject: [PATCH] build_manifest.py: Split the hostname resolution from the requests --- gitlab/build_manifest.py | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/gitlab/build_manifest.py b/gitlab/build_manifest.py index 2560e73..a94ce31 100755 --- a/gitlab/build_manifest.py +++ b/gitlab/build_manifest.py @@ -35,11 +35,23 @@ MANIFEST_TEMPLATE: str = """ def request(path: str) -> Dict[str, str]: gitlab_header: Dict[str, str] = {'JOB_TOKEN': os.environ["CI_JOB_TOKEN"]} - base_url: str = urlparse(os.environ('CI_PROJECT_URL')).hostname + base_url: str = get_hostname(os.environ['CI_PROJECT_URL']) return requests.get(f"https://{base_url}/api/v4/" + path, headers=gitlab_header).json() +def get_hostname(url: str) -> str: + return urlparse(url).hostname + + +def test_get_hostname(): + gitlab = 'https://gitlab.com/example/a_project' + assert get_hostname(gitlab) == 'gitlab.com' + + fdo = 'https://gitlab.freedesktop.org/example/a_project' + assert get_hostname(fdo) == 'gitlab.freedesktop.org' + + def find_repository_sha(module: str, branchname: str) -> Tuple[str, str]: for project in request('projects?search=' + module): if project['name'] != module: -- 2.7.4