From af332a5d1cd05fbd5039e3db3fc53a33a6d5b5ed Mon Sep 17 00:00:00 2001 From: lezi-fun <177434121+lezi-fun@users.noreply.github.com> Date: Tue, 19 May 2026 17:03:54 +0800 Subject: [PATCH] Avoid deleting reused PR branches --- src/review/processor.ts | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/src/review/processor.ts b/src/review/processor.ts index 7e44956..84c93b7 100644 --- a/src/review/processor.ts +++ b/src/review/processor.ts @@ -175,6 +175,28 @@ export async function processScheduledBranchCleanup( continue; } + const hasOtherOpenPullRequestWithSameRef = pullRequests.some((candidate) => { + return ( + candidate.number !== pullRequest.number && + candidate.state === "open" && + candidate.head?.ref === pullRequest.head.ref && + candidate.head.repo?.full_name === `${params.owner}/${params.repo}` + ); + }); + + if (hasOtherOpenPullRequestWithSameRef) { + logger.info( + { + owner: params.owner, + repo: params.repo, + branch: pullRequest.head.ref, + pullNumber: pullRequest.number + }, + "Skipping branch cleanup because another open pull request still uses the same head ref." + ); + continue; + } + if (pullRequest.merged_at) { await deleteBranchIfPresent(octokit, { owner: params.owner,