From 3c90da43bf0dac0c1c59f16f47974fffe12858c5 Mon Sep 17 00:00:00 2001 From: Alexander Hungenberg Date: Sun, 17 Sep 2023 23:12:30 +0200 Subject: [PATCH 1/4] check gitlab finishing its async tasks after creating merge request --- src/foxops/hosters/gitlab.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/foxops/hosters/gitlab.py b/src/foxops/hosters/gitlab.py index 9d035482..4565a196 100644 --- a/src/foxops/hosters/gitlab.py +++ b/src/foxops/hosters/gitlab.py @@ -153,6 +153,24 @@ async def merge_request( with_automerge=with_automerge, ) + # wait until Gitlab finished mergability checks + for _ in range(5): + if merge_request["merge_status"] != "checking": + 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) From 65f8c5fca99acb3b29e90b663c7d40435801f0b9 Mon Sep 17 00:00:00 2001 From: Alexander Hungenberg Date: Sun, 17 Sep 2023 23:13:56 +0200 Subject: [PATCH 2/4] fix --- src/foxops/hosters/gitlab.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/foxops/hosters/gitlab.py b/src/foxops/hosters/gitlab.py index 4565a196..3c6c3652 100644 --- a/src/foxops/hosters/gitlab.py +++ b/src/foxops/hosters/gitlab.py @@ -155,7 +155,7 @@ async def merge_request( # wait until Gitlab finished mergability checks for _ in range(5): - if merge_request["merge_status"] != "checking": + if merge_request["merge_status"] not in ["checking", "unchecked"]: break response = await self.client.get( From 2b9b01deac52fcaae98f066c672fb84e93bbf103 Mon Sep 17 00:00:00 2001 From: Alexander Hungenberg Date: Sun, 17 Sep 2023 23:15:28 +0200 Subject: [PATCH 3/4] fix --- src/foxops/hosters/gitlab.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/foxops/hosters/gitlab.py b/src/foxops/hosters/gitlab.py index 3c6c3652..afac751b 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 @@ -155,7 +156,7 @@ async def merge_request( # wait until Gitlab finished mergability checks for _ in range(5): - if merge_request["merge_status"] not in ["checking", "unchecked"]: + if merge_request["detailed_merge_status"] not in ["checking", "unchecked"]: break response = await self.client.get( From f3916e2a4d7f7892ad838c740945f2048c2bc710 Mon Sep 17 00:00:00 2001 From: Alexander Hungenberg Date: Sun, 17 Sep 2023 23:52:34 +0200 Subject: [PATCH 4/4] fix --- src/foxops/hosters/gitlab.py | 2 +- src/foxops/logger.py | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/src/foxops/hosters/gitlab.py b/src/foxops/hosters/gitlab.py index afac751b..14466901 100644 --- a/src/foxops/hosters/gitlab.py +++ b/src/foxops/hosters/gitlab.py @@ -156,7 +156,7 @@ async def merge_request( # wait until Gitlab finished mergability checks for _ in range(5): - if merge_request["detailed_merge_status"] not in ["checking", "unchecked"]: + if merge_request["detailed_merge_status"] not in ["preparing", "checking", "unchecked"]: break response = await self.client.get( 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,