build_manifest.py: split the request function in two

Make it so it does not depend on env variables so it will be easier
to test.
This commit is contained in:
Jordan Petridis 2018-10-23 22:10:16 +03:00
parent 6772fa76aa
commit 61c5d7b6cf
No known key found for this signature in database
GPG key ID: 902CC06D159744F5

View file

@ -33,13 +33,19 @@ MANIFEST_TEMPLATE: str = """<?xml version="1.0" encoding="UTF-8"?>
</manifest>"""
def request(path: str) -> Dict[str, str]:
gitlab_header: Dict[str, str] = {'JOB_TOKEN': os.environ["CI_JOB_TOKEN"]}
base_url: str = get_hostname(os.environ['CI_PROJECT_URL'])
def request_raw(path: str, token: str, project_url: str) -> Dict[str, str]:
gitlab_header: Dict[str, str] = {'JOB_TOKEN': token }
base_url: str = get_hostname(project_url)
return requests.get(f"https://{base_url}/api/v4/" + path, headers=gitlab_header).json()
def request(path: str) -> Dict[str, str]:
token = os.environ["CI_JOB_TOKEN"]
project_url = os.environ['CI_PROJECT_URL']
return request_raw(path, token, project_url)
def get_hostname(url: str) -> str:
return urlparse(url).hostname