Answer stability round 1: 0 🔴, 1 🟡 (0 misread); read pages until an empty or repeated one, and reword the paging prose

This commit is contained in:
2026-11-27 16:51:50 +01:00
parent afc9ee1653
commit 6700def9c8
4 changed files with 23 additions and 10 deletions
+5 -3
View File
@@ -13,7 +13,7 @@ from forge.reviews import GITEA_DRAFT
POLL_SECONDS = 10
# How long checks_passed waits on Gitea for the checks before it gives up; CI took about 3 minutes in 2026-11. gh's watch waits as long as the checks run.
WAIT_SECONDS = 30 * 60
# How many pull requests one page of Gitea's list holds: its default cap.
# How many pull requests pull_at asks Gitea for in a page; Gitea's default cap is 50.
PAGE_SIZE = 50
# What gh says of a pull request whose head has no check.
NO_CHECKS = "no checks reported"
@@ -37,7 +37,8 @@ def pull_at(forge: Forge, branch: str, head: str, state: typing.Literal["open",
return listed
rows = [line.split("\t") for line in listed.splitlines()]
return next((row[0] for row in rows if row[1:] == [head, "false"]), None)
# Gitea lists at most PAGE_SIZE a page, newest first, and the pull request sought may be older than any number of them, so read each page until one matches or one comes back short. Gitea has no merged state: a merged pull request is a closed one marked merged.
# The pull request sought may be older than any number of others, so read pages, newest first, until one matches or the list ends: an empty page, or one that repeats the last. A short page doesn't end it, since Gitea's admin may cap a page below PAGE_SIZE. Gitea has no merged state: a merged pull request is a closed one marked merged.
last: typing.Any = None
page = 1
while True:
pulls = gitea(run, f"repos/{{owner}}/{{repo}}/pulls?state={'open' if state == 'open' else 'closed'}&limit={PAGE_SIZE}" + (f"&page={page}" if page > 1 else ""))
@@ -48,8 +49,9 @@ def pull_at(forge: Forge, branch: str, head: str, state: typing.Literal["open",
found = next((str(pull["number"]) for pull in pulls if pull["head"]["label"] == branch and pull["head"]["sha"] == head and pull["head"]["repo"]["full_name"] == pull["base"]["repo"]["full_name"] and (state == "open" or pull["merged"] is True)), None)
except (KeyError, TypeError):
return Failure(f"tea api listed pull requests in a shape that can't be read: {str(pulls)[:200]}")
if found or len(pulls) < PAGE_SIZE:
if found or not pulls or pulls == last:
return found
last = pulls
page += 1