From c203ec8e62639c6fed01deaf3d046c8b2e2b33eb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Brunner?= Date: Wed, 10 Jan 2024 11:56:51 +0100 Subject: [PATCH] Report commit message issue in the UI --- app/shared_config_manager/views.py | 30 +++++++++++++++++++----------- 1 file changed, 19 insertions(+), 11 deletions(-) diff --git a/app/shared_config_manager/views.py b/app/shared_config_manager/views.py index 882d043a..38ac9f1a 100644 --- a/app/shared_config_manager/views.py +++ b/app/shared_config_manager/views.py @@ -105,17 +105,25 @@ def key_format(key: str) -> str: if "GITHUB_TOKEN" in os.environ: headers["Authorization"] = f"token {os.environ['GITHUB_TOKEN']}" - commit_response = requests.get( - f"https://api.github.com/repos/{match.group(1)}/commits/{slave['hash']}", headers=headers - ) - commit_response.raise_for_status() - commit_json = commit_response.json() - commit_details: list[Union[str, tuple[str, str]]] = [ - (commit_json["html_url"], commit_json["sha"]), - f"Author: {commit_json['commit']['author']['name']}", - f"Date: {commit_json['commit']['author']['date']}", - f"Message: {commit_json['commit']['message']}", - ] + if "hash" not in slave: + _slave_status.append((slave, ["No provided hash"])) + else: + commit_response = requests.get( + f"https://api.github.com/repos/{match.group(1)}/commits/{slave['hash']}", + headers=headers, + ) + if not commit_response.ok: + _slave_status.append( + (slave, [f"Unable to get the commit status: {commit_response.reason}"]) + ) + else: + commit_json = commit_response.json() + commit_details: list[Union[str, tuple[str, str]]] = [ + (commit_json["html_url"], commit_json["sha"]), + f"Author: {commit_json['commit']['author']['name']}", + f"Date: {commit_json['commit']['author']['date']}", + f"Message: {commit_json['commit']['message']}", + ] else: commit_details = (