bridge: replace the mirror PR when a GitHub PR is retargeted to another base
All checks were successful
check / gate (push) Successful in 8s
canary / probe (push) Successful in 5s

The mirror kept its creation-time base forever. eternitas #167 was stacked
on fix/one-hallway, retargeted to main after #166 merged; ci.yml
(pull_request: branches [main]) then silently never ran for it, while
unfiltered workflows did. An edited event triggers nothing, so close the
stale mirror and open a fresh one on the new base (runs CI at once).
An unknown base is left alone, never guessed.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Kit OC5
2026-09-23 16:16:15 -04:00
parent 9e9eb08d96
commit 4bb4893131
2 changed files with 32 additions and 1 deletions

View File

@@ -202,7 +202,17 @@ def sync_prs(repo: str) -> list[str]:
wanted.add(tag)
heads.append(pr["head"]["sha"])
if tag in ours:
continue
cur = (ours[tag].get("base") or {}).get("ref")
if cur is None or cur == pr["base"]["ref"]: # unknown base: never guess, leave it
continue
# Retargeted on GitHub (e.g. a stacked PR moved to main after its
# parent merged). The mirror kept the OLD base, so workflows filtered
# on the base (`pull_request: branches: [main]`) silently stopped
# running: eternitas #167, 09-23. Replace the mirror: an "edited"
# event triggers nothing, a freshly opened PR runs CI at once.
gitea("PATCH", f"/repos/{WG_OWNER}/{repo}/pulls/{ours[tag]['number']}", {"state": "closed"})
print(f" {repo}: GH#{pr['number']} retargeted {cur} -> "
f"{pr['base']['ref']}: replacing its mirror PR")
st, _ = gitea(
"POST",
f"/repos/{WG_OWNER}/{repo}/pulls",