Skip to content

Commit d40e4fb

Browse files
⚙️ [Maintenance]: Delete branches of superseded Auto-Update PRs when closing them (#155)
The Auto-Update workflow now automatically deletes branches associated with superseded PRs when closing them, preventing stale branches from accumulating in the repository. - Fixes #154 ## Branch cleanup for superseded Auto-Update PRs When the `Update-FontsData` workflow creates a new Auto-Update PR and closes any superseded open Auto-Update PRs, the associated branches (e.g., `auto-update-20260210-101656`) are now also deleted. The PR list query now includes `headRefName` to retrieve branch names, and after closing each superseded PR, the branch is deleted via the GitHub API. The deletion is wrapped in a try-catch block to prevent workflow failures if the branch has already been deleted or permissions are insufficient. --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: MariusStorhaug <17722253+MariusStorhaug@users.noreply.github.com> Co-authored-by: Marius Storhaug <marstor@hotmail.com>
1 parent e3de578 commit d40e4fb

1 file changed

Lines changed: 15 additions & 1 deletion

File tree

scripts/Update-FontsData.ps1

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ LogGroup 'Process changes' {
161161
Write-Output "Found new PR #$($newPR.number): $($newPR.title)"
162162

163163
# Find existing open Auto-Update PRs (excluding the one we just created)
164-
$existingPRsJson = Run gh pr list --repo $repoName --state open --search 'Auto-Update in:title' --json 'number,title'
164+
$existingPRsJson = Run gh pr list --repo $repoName --state open --search 'Auto-Update in:title' --json 'number,title,headRefName'
165165
$existingPRs = $existingPRsJson | ConvertFrom-Json | Where-Object { $_.number -ne $newPR.number }
166166

167167
if ($existingPRs) {
@@ -181,6 +181,20 @@ The font data has been updated in the newer PR. Please refer to #$($newPR.number
181181
Run gh pr close $pr.number --repo $repoName
182182

183183
Write-Output "Successfully closed PR #$($pr.number)"
184+
185+
# Delete the branch associated with the closed PR
186+
$branchName = $pr.headRefName
187+
if ($branchName) {
188+
Write-Output "Deleting branch: $branchName"
189+
$null = Run gh api -X DELETE "repos/$repoName/git/refs/heads/$branchName"
190+
if ($LASTEXITCODE -eq 0) {
191+
Write-Output "Successfully deleted branch: $branchName"
192+
} else {
193+
Write-Warning "Failed to delete branch $branchName (exit code $LASTEXITCODE)"
194+
}
195+
} else {
196+
Write-Warning "Could not determine branch name for PR #$($pr.number)"
197+
}
184198
}
185199
} else {
186200
Write-Output 'No existing open Auto-Update PRs to close.'

0 commit comments

Comments
 (0)