Compare commits
1 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| afc9ee1653 |
+16
-9
@@ -13,6 +13,8 @@ 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.
|
||||
PAGE_SIZE = 50
|
||||
# What gh says of a pull request whose head has no check.
|
||||
NO_CHECKS = "no checks reported"
|
||||
|
||||
@@ -35,15 +37,20 @@ 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 50 a page; the pull request sought is among the newest. Gitea has no merged state: a merged pull request is a closed one marked merged.
|
||||
pulls = gitea(run, f"repos/{{owner}}/{{repo}}/pulls?state={'open' if state == 'open' else 'closed'}&limit=50")
|
||||
if isinstance(pulls, Failure):
|
||||
return pulls
|
||||
try:
|
||||
# Match the label, not the ref: once origin deletes a merged branch, Gitea reports its ref as refs/pull/<N>/head.
|
||||
return 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]}")
|
||||
# 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.
|
||||
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 ""))
|
||||
if isinstance(pulls, Failure):
|
||||
return pulls
|
||||
try:
|
||||
# Match the label, not the ref: once origin deletes a merged branch, Gitea reports its ref as refs/pull/<N>/head.
|
||||
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:
|
||||
return found
|
||||
page += 1
|
||||
|
||||
|
||||
@dataclasses.dataclass(frozen=True)
|
||||
|
||||
+35
-1
@@ -9,7 +9,7 @@ import unittest
|
||||
|
||||
sys.path.insert(0, str(pathlib.Path(__file__).resolve().parents[1]))
|
||||
|
||||
from forge.pulls import BEHIND, CheckFailed, checks_now, checks_passed, CONFLICTS, open_pull, other_base, Pending, POLL_SECONDS, ready_pulls, ReadyPull, required_checks, unmergeable, WAIT_SECONDS
|
||||
from forge.pulls import BEHIND, CheckFailed, checks_now, checks_passed, CONFLICTS, merged_pull, open_pull, other_base, Pending, POLL_SECONDS, ready_pulls, ReadyPull, required_checks, unmergeable, WAIT_SECONDS
|
||||
from failure import Failure
|
||||
from forge.commands import forge_of, gitea, runner, url_beside
|
||||
|
||||
@@ -50,6 +50,40 @@ class OpenPull(unittest.TestCase):
|
||||
self.assertEqual(open_pull("tea", "item-3", "abc", lambda command: LONG).reason, f"tea api listed pull requests in a shape that can't be read: {LONG[:200]}")
|
||||
|
||||
|
||||
def gitea_pulls(newer: int, sought: dict) -> typing.Callable[[list[str]], str]:
|
||||
"""A fake tea listing `newer` pull requests, newest first, then `sought` last: it serves the `limit` and `page` of the endpoint like Gitea."""
|
||||
def pull(number: int, label: str, sha: str, merged: bool) -> dict:
|
||||
return {"number": number, "merged": merged, "head": {"label": label, "sha": sha, "repo": {"full_name": "o/r"}}, "base": {"repo": {"full_name": "o/r"}}}
|
||||
everything = [pull(1000 - n, f"other-{n}", "f" * 40, True) for n in range(newer)] + [pull(sought["number"], sought["label"], sought["sha"], sought["merged"])]
|
||||
def run(command: list[str]) -> str:
|
||||
query = dict(part.split("=") for part in command[-1].split("?")[1].split("&"))
|
||||
limit, page = int(query["limit"]), int(query.get("page", "1"))
|
||||
return json.dumps(everything[(page - 1) * limit:page * limit])
|
||||
return run
|
||||
|
||||
|
||||
class PullsBeyondTheFirstPage(unittest.TestCase):
|
||||
SOUGHT = {"number": 652, "label": "item-3", "sha": "abc", "merged": True}
|
||||
|
||||
def test_finds_a_merged_pull_request_that_more_than_50_newer_ones_follow(self):
|
||||
self.assertEqual(merged_pull("tea", "item-3", "abc", gitea_pulls(120, self.SOUGHT)), "652")
|
||||
|
||||
def test_finds_one_that_is_the_first_after_a_full_page(self):
|
||||
self.assertEqual(merged_pull("tea", "item-3", "abc", gitea_pulls(50, self.SOUGHT)), "652")
|
||||
|
||||
def test_finds_none_after_the_last_page_where_none_matches(self):
|
||||
self.assertIsNone(merged_pull("tea", "item-9", "abc", gitea_pulls(120, self.SOUGHT)))
|
||||
|
||||
def test_asks_for_no_page_past_the_one_that_comes_back_short(self):
|
||||
asked = []
|
||||
run = gitea_pulls(70, self.SOUGHT)
|
||||
merged_pull("tea", "item-9", "abc", lambda command: asked.append(command[-1]) or run(command))
|
||||
self.assertEqual(asked, ["repos/{owner}/{repo}/pulls?state=closed&limit=50", "repos/{owner}/{repo}/pulls?state=closed&limit=50&page=2"])
|
||||
|
||||
def test_finds_an_open_pull_request_the_same_way(self):
|
||||
self.assertEqual(open_pull("tea", "item-3", "abc", gitea_pulls(120, {**self.SOUGHT, "merged": False})), "652")
|
||||
|
||||
|
||||
class Unmergeable(unittest.TestCase):
|
||||
def gh(self, mergeable: str, state: str) -> str | None | Failure:
|
||||
commands: list[list[str]] = []
|
||||
|
||||
@@ -3711,3 +3711,23 @@ Read most (opens and searches):
|
||||
- `bin/release_plan/release_standing.py` 3
|
||||
- `CHANGELOG.md` 1
|
||||
- `bin/deploy_release/cut.py` 1
|
||||
|
||||
## Reading cost, chunk 7361c9bb3e9a, finished 2026-11-27T14:31:28Z
|
||||
|
||||
48295 new input tokens before the first commit.
|
||||
|
||||
Read most (opens and searches):
|
||||
|
||||
- `agents/stability-reviewer.md` 3
|
||||
- `README.md` 1
|
||||
- `agents/systems-architect.md` 1
|
||||
- `skills/larv-review/SKILL.md` 1
|
||||
|
||||
## Reading cost, chunk 73ef8355db51, finished 2026-11-27T14:52:23Z
|
||||
|
||||
61386 new input tokens before the first commit.
|
||||
|
||||
Read most (opens and searches):
|
||||
|
||||
- `agents/stability-reviewer.md` 3
|
||||
- `skills/larv-review/SKILL.md` 2
|
||||
|
||||
Reference in New Issue
Block a user