From 0f63368de54e88155bee2ec561f16d10e3f5fb71 Mon Sep 17 00:00:00 2001 From: Alexander Hungenberg Date: Mon, 18 Sep 2023 00:01:51 +0200 Subject: [PATCH] check gitlab finishes its async tasks after creating merge request (#413) --- src/foxops/hosters/gitlab.py | 19 +++++++++++++++++++ src/foxops/logger.py | 3 +++ 2 files changed, 22 insertions(+) diff --git a/src/foxops/hosters/gitlab.py b/src/foxops/hosters/gitlab.py index 9d035482..14466901 100644 --- a/src/foxops/hosters/gitlab.py +++ b/src/foxops/hosters/gitlab.py @@ -45,6 +45,7 @@ class MergeRequest(TypedDict): sha: str state: str merge_status: str + detailed_merge_status: str merge_commit_sha: str | None head_pipeline: dict | None @@ -153,6 +154,24 @@ async def merge_request( with_automerge=with_automerge, ) + # wait until Gitlab finished mergability checks + for _ in range(5): + if merge_request["detailed_merge_status"] not in ["preparing", "checking", "unchecked"]: + break + + response = await self.client.get( + f"/projects/{quote_plus(incarnation_repository)}/merge_requests/{merge_request['iid']}" + ) + response.raise_for_status() + merge_request = response.json() + + await asyncio.sleep(5) + else: + logger.warning( + f"Merge request {merge_request['web_url']} is still in state 'checking' after 5 retries, " + f"continuing with the assumption that it is mergeable" + ) + if with_automerge: logger.info(f"Triggering automerge for the new Merge Request {merge_request['web_url']}") merge_request = await self._automerge_merge_request(merge_request) diff --git a/src/foxops/logger.py b/src/foxops/logger.py index 55daec59..eec8ce23 100644 --- a/src/foxops/logger.py +++ b/src/foxops/logger.py @@ -34,6 +34,9 @@ def configure_uvicorn_logging(): def setup_logging(level: int | str) -> None: + if structlog.is_configured(): + return + shared_processors: Sequence[Processor] = [ merge_contextvars, structlog.stdlib.add_log_level,