From 23b7848be6adea68ce96ece7c615bb9bf6737add Mon Sep 17 00:00:00 2001 From: Lilleman auf Larv Date: Tue, 10 Nov 2026 11:13:26 +0100 Subject: [PATCH] =?UTF-8?q?Answer=20stability=20round=202:=201=20?= =?UTF-8?q?=F0=9F=94=B4,=200=20=F0=9F=9F=A1=20(0=20misread);=20match=20Git?= =?UTF-8?q?ea=20pull=20requests=20by=20head=20label,=20which=20survives=20?= =?UTF-8?q?origin=20deleting=20a=20merged=20branch?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bin/chunk_pr/test_chunk_pr.py | 4 ++-- bin/deploy_release/forge.py | 3 ++- bin/deploy_release/test_deploy_release.py | 2 +- bin/larv_review/test_larv_review.py | 2 +- 4 files changed, 6 insertions(+), 5 deletions(-) diff --git a/bin/chunk_pr/test_chunk_pr.py b/bin/chunk_pr/test_chunk_pr.py index 9b52ba48..6efed6e0 100644 --- a/bin/chunk_pr/test_chunk_pr.py +++ b/bin/chunk_pr/test_chunk_pr.py @@ -51,7 +51,7 @@ class Checkout: if command == GH_LIST: return f"12\t{HEAD}\tfalse\n" if self.open else "" if command == TEA_LIST: - return json.dumps([{"number": 12, "head": {"ref": "item-7", "sha": HEAD, "repo": {"full_name": "me/project"}}, "base": {"repo": {"full_name": "me/project"}}}] if self.open else []) + return json.dumps([{"number": 12, "head": {"ref": "item-7", "label": "item-7", "sha": HEAD, "repo": {"full_name": "me/project"}}, "base": {"repo": {"full_name": "me/project"}}}] if self.open else []) if command in (GH_SETTINGS, TEA_SETTINGS): return json.dumps({setting: True for setting in self.allowed}) return "" @@ -231,7 +231,7 @@ class Clean(unittest.TestCase): if command == ["gh", "pr", "list", "--head", "item-7", "--state", "merged", *GH_LIST[5:]] and self.url == GITHUB: return f"12\t{self.merged_at}\tfalse\n" if self.merged_at else "" if command == ["tea", "api", "repos/{owner}/{repo}/pulls?state=closed&limit=50"] and self.url == GITEA: - return json.dumps([{"number": 12, "merged": self.merged_at is not None, "head": {"ref": "item-7", "sha": self.merged_at or self.head, "repo": {"full_name": "me/project"}}, "base": {"repo": {"full_name": "me/project"}}}]) + return json.dumps([{"number": 12, "merged": self.merged_at is not None, "head": {"ref": "refs/pull/12/head" if self.merged_at else "item-7", "label": "item-7", "sha": self.merged_at or self.head, "repo": {"full_name": "me/project"}}, "base": {"repo": {"full_name": "me/project"}}}]) if command[0] != "git": return Failure(f"the fake forge doesn't answer {command}") done = subprocess.run(command, cwd=folder, capture_output=True, encoding="utf-8", env=isolated_env()) diff --git a/bin/deploy_release/forge.py b/bin/deploy_release/forge.py index 924c027d..7aa44caa 100644 --- a/bin/deploy_release/forge.py +++ b/bin/deploy_release/forge.py @@ -69,7 +69,8 @@ def pull_at(forge: Forge, branch: str, head: str, state: typing.Literal["open", if isinstance(pulls, Failure): return pulls try: - return next((str(pull["number"]) for pull in pulls if pull["head"]["ref"] == 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) + # Match the label, not the ref: once origin deletes a merged branch, Gitea reports its ref as refs/pull//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]}") diff --git a/bin/deploy_release/test_deploy_release.py b/bin/deploy_release/test_deploy_release.py index 008bd0f2..4c12e95c 100644 --- a/bin/deploy_release/test_deploy_release.py +++ b/bin/deploy_release/test_deploy_release.py @@ -177,7 +177,7 @@ def merge(number, guard): opened = [found for found in state["pulls"] if found["state"] == "open"] if forge == "tea" and args == ["api", "repos/{owner}/{repo}/pulls?state=open&limit=50"]: repo = lambda found: {"full_name": "fork/r" if found["fork"] else "o/r"} - print(json.dumps([{"number": found["number"], "head": {"ref": found["head"], "sha": sha(found), "repo": repo(found)}, "base": {"repo": {"full_name": "o/r"}}} for found in opened])) + print(json.dumps([{"number": found["number"], "head": {"ref": found["head"], "label": found["head"], "sha": sha(found), "repo": repo(found)}, "base": {"repo": {"full_name": "o/r"}}} for found in opened])) elif forge == "gh" and args[:3] == ["pr", "list", "--head"] and args[4:6] == ["--json", "number,headRefOid,isCrossRepository"]: for found in opened: if found["head"] == args[3]: diff --git a/bin/larv_review/test_larv_review.py b/bin/larv_review/test_larv_review.py index 26709d66..f7a8a488 100644 --- a/bin/larv_review/test_larv_review.py +++ b/bin/larv_review/test_larv_review.py @@ -736,7 +736,7 @@ class LarvReviewTool(unittest.TestCase): def fake_tea(self, number, head): """Puts a tea on PATH whose API lists one open pull request, number, from origin's chunk at head.""" - pull = f'{{"number": {number}, "head": {{"ref": "chunk", "sha": "{head}", "repo": {{"full_name": "a/b"}}}}, "base": {{"repo": {{"full_name": "a/b"}}}}}}' + pull = f'{{"number": {number}, "head": {{"ref": "chunk", "label": "chunk", "sha": "{head}", "repo": {{"full_name": "a/b"}}}}, "base": {{"repo": {{"full_name": "a/b"}}}}}}' self.fake_tea_script(f"echo '[{pull}]'") def fake_tea_script(self, body):