build_manifest.py: Handle bad requests

This commit is contained in:
Jordan Petridis 2018-10-24 19:40:30 +03:00
parent 10b1812e70
commit 412d980b62
No known key found for this signature in database
GPG key ID: 902CC06D159744F5

View file

@ -56,8 +56,12 @@ CURRENT_BRANCH: str = os.environ['CI_COMMIT_REF_NAME']
def request_raw(path: str, token: str, project_url: str) -> List[Dict[str, str]]:
gitlab_header: Dict[str, str] = {'JOB_TOKEN': token }
base_url: str = get_hostname(project_url)
resp = requests.get(f"https://{base_url}/api/v4/" + path, headers=gitlab_header)
return requests.get(f"https://{base_url}/api/v4/" + path, headers=gitlab_header).json()
if not resp.ok:
return None
return resp.json()
def request(path: str) -> List[Dict[str, str]]:
@ -97,6 +101,9 @@ def test_get_project_branch():
failure = get_project_branch(id, 'why-would-anyone-chose-this-branch-name')
assert failure is None
failure2 = get_project_branch("invalid-id", '1.12')
assert failure2 is None
# Documentation: https://docs.gitlab.com/ce/api/projects.html#list-user-projects
def search_user_namespace(user: str, project: str) -> Dict[str, str]: