Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

check gitlab finishing its async tasks after creating merge request #413

Merged
merged 4 commits into from
Sep 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading