Fix branch-cleanup: use head.label when head.ref is rewritten

Forgejo rewrites head.ref to refs/pull/N/head once the source branch
is deleted from the remote. The original branch name is preserved in
head.label. This was causing 188 out of 246 merged PRs to be missed.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
Erich Blume 2026-02-22 16:15:26 -08:00
commit 35630f41d1

View file

@ -188,7 +188,12 @@ def get_merged_pr_branches(client: httpx.Client, console: Console) -> set[str]:
break
for pr in prs:
if pr.get("merged"):
ref = pr.get("head", {}).get("ref", "")
head = pr.get("head", {})
ref = head.get("ref", "")
# Forgejo rewrites ref to refs/pull/N/head once the
# source branch is deleted; the original name is in label
if ref.startswith("refs/pull/"):
ref = head.get("label", "")
if ref and ref not in PROTECTED_BRANCHES:
merged_branches.add(ref)
page += 1