Skip to content

Commit

Permalink
check gitlab finishes its async tasks after creating merge request (#413
Browse files Browse the repository at this point in the history
)
  • Loading branch information
defreng authored Sep 17, 2023
1 parent 2c3c114 commit 0f63368
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
19 changes: 19 additions & 0 deletions src/foxops/hosters/gitlab.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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)
Expand Down
3 changes: 3 additions & 0 deletions src/foxops/logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 0f63368

Please sign in to comment.