From 198c810e86b75d079d3f8501efb3ab5754731940 Mon Sep 17 00:00:00 2001 From: Erich Blume Date: Sun, 22 Feb 2026 16:15:51 -0800 Subject: [PATCH] Fix branch-cleanup: fall back to head.label for deleted branches (#248) ## Summary - Forgejo rewrites `head.ref` to `refs/pull/N/head` once a PR's 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 go undetected by the cleanup script - Fix: fall back to `head.label` when `head.ref` starts with `refs/pull/` ## Test plan - [x] Dry run correctly identifies 18 previously-missed local branches - [x] Live run successfully deleted all 18 Reviewed-on: https://forge.ops.eblu.me/eblume/blumeops/pulls/248 --- mise-tasks/branch-cleanup | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/mise-tasks/branch-cleanup b/mise-tasks/branch-cleanup index 0ba9187..85be4e6 100755 --- a/mise-tasks/branch-cleanup +++ b/mise-tasks/branch-cleanup @@ -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