Do not notify GitHub statuses if nothing changed
This commit is contained in:
parent
8b10c209bd
commit
8bfd75d049
2 changed files with 32 additions and 33 deletions
|
|
@ -1,4 +1,3 @@
|
||||||
import logging
|
|
||||||
from dataclasses import dataclass
|
from dataclasses import dataclass
|
||||||
from enum import Enum
|
from enum import Enum
|
||||||
from typing import Any
|
from typing import Any
|
||||||
|
|
@ -8,8 +7,6 @@ import httpx
|
||||||
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:
|
||||||
|
|
@ -19,7 +16,6 @@ async def _github_request(method: str, url: str, json: Any = None) -> Any:
|
||||||
}
|
}
|
||||||
if settings.github_token:
|
if settings.github_token:
|
||||||
headers["Authorization"] = f"token {settings.github_token}"
|
headers["Authorization"] = f"token {settings.github_token}"
|
||||||
_logger.debug("%s %s", method, full_url)
|
|
||||||
response = await client.request(method, full_url, headers=headers, json=json)
|
response = await client.request(method, full_url, headers=headers, json=json)
|
||||||
if response.status_code == 404:
|
if response.status_code == 404:
|
||||||
raise NotFoundOnGitHub(f"GitHub URL not found: {full_url}.")
|
raise NotFoundOnGitHub(f"GitHub URL not found: {full_url}.")
|
||||||
|
|
|
||||||
|
|
@ -173,7 +173,7 @@ class Build(BaseModel):
|
||||||
elif self.status == BuildStatus.failed:
|
elif self.status == BuildStatus.failed:
|
||||||
_logger.info(f"Marking failed {self} for reinitialization.")
|
_logger.info(f"Marking failed {self} for reinitialization.")
|
||||||
await k8s.delete_job(self.name, job_kind=k8s.DeploymentMode.initialize)
|
await k8s.delete_job(self.name, job_kind=k8s.DeploymentMode.initialize)
|
||||||
await self._patch(init_status=BuildInitStatus.todo, desired_replicas=0)
|
if await self._patch(init_status=BuildInitStatus.todo, desired_replicas=0):
|
||||||
await github.notify_status(
|
await github.notify_status(
|
||||||
self.repo,
|
self.repo,
|
||||||
self.git_commit,
|
self.git_commit,
|
||||||
|
|
@ -241,7 +241,7 @@ class Build(BaseModel):
|
||||||
if self.init_status == BuildInitStatus.started:
|
if self.init_status == BuildInitStatus.started:
|
||||||
return
|
return
|
||||||
_logger.info(f"Initialization job started for {self}.")
|
_logger.info(f"Initialization job started for {self}.")
|
||||||
await self._patch(init_status=BuildInitStatus.started, desired_replicas=0)
|
if await self._patch(init_status=BuildInitStatus.started, desired_replicas=0):
|
||||||
await github.notify_status(
|
await github.notify_status(
|
||||||
self.repo,
|
self.repo,
|
||||||
self.git_commit,
|
self.git_commit,
|
||||||
|
|
@ -255,7 +255,7 @@ class Build(BaseModel):
|
||||||
# succeeded old initialization jobs after a controller restart.
|
# succeeded old initialization jobs after a controller restart.
|
||||||
return
|
return
|
||||||
_logger.info(f"Initialization job succeded for {self}, starting.")
|
_logger.info(f"Initialization job succeded for {self}, starting.")
|
||||||
await self._patch(init_status=BuildInitStatus.succeeded, desired_replicas=1)
|
if await self._patch(init_status=BuildInitStatus.succeeded, desired_replicas=1):
|
||||||
await github.notify_status(
|
await github.notify_status(
|
||||||
self.repo,
|
self.repo,
|
||||||
self.git_commit,
|
self.git_commit,
|
||||||
|
|
@ -269,7 +269,7 @@ class Build(BaseModel):
|
||||||
# restarting, and is notified of existing initialization jobs.
|
# restarting, and is notified of existing initialization jobs.
|
||||||
return
|
return
|
||||||
_logger.info(f"Initialization job failed for {self}.")
|
_logger.info(f"Initialization job failed for {self}.")
|
||||||
await self._patch(init_status=BuildInitStatus.failed, desired_replicas=0)
|
if await self._patch(init_status=BuildInitStatus.failed, desired_replicas=0):
|
||||||
await github.notify_status(
|
await github.notify_status(
|
||||||
self.repo,
|
self.repo,
|
||||||
self.git_commit,
|
self.git_commit,
|
||||||
|
|
@ -332,7 +332,10 @@ class Build(BaseModel):
|
||||||
"path": "/metadata/finalizers",
|
"path": "/metadata/finalizers",
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
if ops:
|
||||||
await k8s.patch_deployment(self.deployment_name, ops, not_found_ok)
|
await k8s.patch_deployment(self.deployment_name, ops, not_found_ok)
|
||||||
|
return True
|
||||||
|
return False
|
||||||
|
|
||||||
|
|
||||||
class Repo(BaseModel):
|
class Repo(BaseModel):
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue