From 412d980b62c84def2cfb34202a6cffae1bfe864b Mon Sep 17 00:00:00 2001 From: Jordan Petridis Date: Wed, 24 Oct 2018 19:40:30 +0300 Subject: [PATCH] build_manifest.py: Handle bad requests --- gitlab/build_manifest.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/gitlab/build_manifest.py b/gitlab/build_manifest.py index 9ec7573d1d..181e20e5db 100755 --- a/gitlab/build_manifest.py +++ b/gitlab/build_manifest.py @@ -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]: