Pass over an item whose pull request awaits a person's merge, and hold a sentence about several named things to each
CI / tests (pull_request) Failing after 3m42s

This commit is contained in:
Lilleman
2026-11-19 21:54:43 +01:00
parent 06a1398196
commit 00975177ad
22 changed files with 312 additions and 27 deletions
+31
View File
@@ -2,10 +2,12 @@
import dataclasses
import fnmatch
import json
import re
import typing
from failure import Failure
from forge.commands import Forge, gitea, Run
from forge.reviews import GITEA_DRAFT
# How long checks_passed waits between two reads: of the head commit's status on Gitea, or of gh's watch while it reports no checks.
POLL_SECONDS = 10
@@ -44,6 +46,35 @@ def pull_at(forge: Forge, branch: str, head: str, state: typing.Literal["open",
return Failure(f"tea api listed pull requests in a shape that can't be read: {str(pulls)[:200]}")
@dataclasses.dataclass(frozen=True)
class ReadyPull:
"""An open pull request from one of origin's own branches that is no draft."""
number: str
url: str
# The commit ID of its head.
head: str
def ready_pulls(forge: Forge, run: Run) -> list[ReadyPull] | Failure:
"""Each open pull request from origin's own branches that is no draft, which Gitea tells by its title (GITEA_DRAFT). A row whose number or head is no number or commit ID is left out, since callers pass them to git."""
if forge == "gh":
# 100 is the most GitHub's API lists a page; gh lists 30 unless told.
listed = run(["gh", "pr", "list", "--limit", "100", "--json", "number,url,headRefOid,isDraft,isCrossRepository", "--template", "{{range .}}{{.number}}\t{{.url}}\t{{.headRefOid}}\t{{.isDraft}}\t{{.isCrossRepository}}\n{{end}}"])
if isinstance(listed, Failure):
return listed
rows = [line.split("\t") for line in listed.splitlines()]
found = [ReadyPull(*row[:3]) for row in rows if row[3:] == ["false", "false"]]
else:
pulls = gitea(run, "repos/{owner}/{repo}/pulls?state=open&limit=50")
if isinstance(pulls, Failure):
return pulls
try:
found = [ReadyPull(str(pull["number"]), pull["html_url"], pull["head"]["sha"]) for pull in pulls if pull["head"]["repo"]["full_name"] == pull["base"]["repo"]["full_name"] and not pull["title"].upper().startswith(GITEA_DRAFT)]
except (AttributeError, KeyError, TypeError):
return Failure(f"tea api listed pull requests in a shape that can't be read: {str(pulls)[:200]}")
return [pull for pull in found if pull.number.isascii() and pull.number.isdigit() and isinstance(pull.head, str) and re.fullmatch(r"[0-9a-f]{40,64}", pull.head)]
def required_checks(forge: Forge, base: str, run: Run) -> set[str] | Failure:
"""The checks, or glob patterns of checks, that the forge's protection of the branch base requires before a merge. None on GitHub, where gh's watch covers them.