From 90513736535b20df9afba4560d5e345eba973c3b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Bidoul?= Date: Thu, 31 Aug 2023 21:04:04 +0200 Subject: [PATCH] Ignore and log GitHub commit status creation errors --- src/runboat/github.py | 27 ++++++++++++++++++--------- 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/src/runboat/github.py b/src/runboat/github.py index 524c468..db388f9 100644 --- a/src/runboat/github.py +++ b/src/runboat/github.py @@ -1,3 +1,4 @@ +import logging from enum import Enum from typing import Any @@ -7,6 +8,8 @@ from pydantic import BaseModel, validator from .exceptions import NotFoundOnGitHub from .settings import settings +_logger = logging.getLogger(__name__) + async def _github_request(method: str, url: str, json: Any = None) -> Any: async with httpx.AsyncClient() as client: @@ -67,12 +70,18 @@ async def notify_status( if settings.disable_commit_statuses: return # https://docs.github.com/en/rest/reference/repos#create-a-commit-status - await _github_request( - "POST", - f"/repos/{repo}/statuses/{sha}", - json={ - "state": state, - "target_url": target_url, - "context": "runboat/build", - }, - ) + try: + await _github_request( + "POST", + f"/repos/{repo}/statuses/{sha}", + json={ + "state": state, + "target_url": target_url, + "context": "runboat/build", + }, + ) + except httpx.HTTPStatusError as e: + _logger.error( + f"Failed to post GitHub commit status (code {e.response.status_code}):\n" + f"{e.response.text}" + )