Ignore and log GitHub commit status creation errors
This commit is contained in:
parent
02d7fafb21
commit
9051373653
1 changed files with 18 additions and 9 deletions
|
|
@ -1,3 +1,4 @@
|
||||||
|
import logging
|
||||||
from enum import Enum
|
from enum import Enum
|
||||||
from typing import Any
|
from typing import Any
|
||||||
|
|
||||||
|
|
@ -7,6 +8,8 @@ from pydantic import BaseModel, validator
|
||||||
from .exceptions import NotFoundOnGitHub
|
from .exceptions import NotFoundOnGitHub
|
||||||
from .settings import settings
|
from .settings import settings
|
||||||
|
|
||||||
|
_logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
async def _github_request(method: str, url: str, json: Any = None) -> Any:
|
async def _github_request(method: str, url: str, json: Any = None) -> Any:
|
||||||
async with httpx.AsyncClient() as client:
|
async with httpx.AsyncClient() as client:
|
||||||
|
|
@ -67,12 +70,18 @@ async def notify_status(
|
||||||
if settings.disable_commit_statuses:
|
if settings.disable_commit_statuses:
|
||||||
return
|
return
|
||||||
# https://docs.github.com/en/rest/reference/repos#create-a-commit-status
|
# https://docs.github.com/en/rest/reference/repos#create-a-commit-status
|
||||||
await _github_request(
|
try:
|
||||||
"POST",
|
await _github_request(
|
||||||
f"/repos/{repo}/statuses/{sha}",
|
"POST",
|
||||||
json={
|
f"/repos/{repo}/statuses/{sha}",
|
||||||
"state": state,
|
json={
|
||||||
"target_url": target_url,
|
"state": state,
|
||||||
"context": "runboat/build",
|
"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}"
|
||||||
|
)
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue