Say as each step of deploy-release --cut finishes, end on a Done line, delete the merged release branch, and wait for the checks main's protection requires

This commit is contained in:
2026-11-09 02:44:40 +01:00
parent daf6a38fc3
commit 94aa8bafbf
4 changed files with 114 additions and 20 deletions
+25 -7
View File
@@ -68,29 +68,47 @@ def create_pull(forge: Forge, branch: str, base: str, title: str, run: Run) -> F
return created if isinstance(created, Failure) else None
def checks_passed(forge: Forge, number: str, head: str, run: Run, sleep: typing.Callable[[float], None] = time.sleep) -> Failure | None:
"""None once every check on pull request number, whose head commit is head, has passed, or where it has none; a Failure where one fails."""
def checks_passed(forge: Forge, number: str, head: str, base: str, run: Run, sleep: typing.Callable[[float], None] = time.sleep) -> Failure | None:
"""None once every check on pull request number, whose head commit is head, has passed, or where it has none; a Failure where one fails.
On Gitea it also waits for each check the protection of base requires to report: a check CI has yet to queue is no status at all.
"""
if forge == "gh":
watched = run(["gh", "pr", "checks", number, "--watch", "--fail-fast"])
if isinstance(watched, Failure) and "no checks reported" not in watched.reason:
return watched
return None
required = required_checks(base, run)
if isinstance(required, Failure):
return required
while True:
status = gitea(run, f"repos/{{owner}}/{{repo}}/commits/{head}/status")
if isinstance(status, Failure):
return status
try:
count, state = status["total_count"], status["state"]
except (KeyError, TypeError):
passed = {check["context"] for check in status.get("statuses") or [] if check["status"] == "success"}
except (KeyError, TypeError, AttributeError):
return Failure(f"tea api printed no commit status for {head}: {str(status)[:200]}")
# Gitea reads a commit with no status as pending, with total_count 0.
if count == 0 or state == "success":
return None
if state != "pending":
if state not in ("pending", "success"):
return Failure(f"a check on pull request {number} ended in {state}")
# Gitea reads a commit with no status as pending, with total_count 0.
if (count == 0 or state == "success") and required <= passed:
return None
sleep(POLL_SECONDS)
def required_checks(base: str, run: Run) -> set[str] | Failure:
"""The checks Gitea's protection of the branch base requires before a merge."""
protections = gitea(run, "repos/{owner}/{repo}/branch_protections")
if isinstance(protections, Failure):
return protections
try:
return {context for rule in protections or [] if base in (rule.get("rule_name"), rule.get("branch_name")) and rule.get("enable_status_check") for context in rule.get("status_check_contexts") or []}
except (AttributeError, TypeError):
return Failure(f"tea api listed branch protections in a shape that can't be read: {str(protections)[:200]}")
def merge(forge: Forge, number: str, head: str, run: Run) -> Failure | None:
"""Merge pull request number, fast-forward only on Gitea and by rebase on GitHub. The forge refuses where the pull request's head is no longer head."""
if forge == "gh":