Azure / Azure/azure-rest-api-specs
[EngSys] Cleanup stale branches from merged PRs
- Dominant language
- TypeSpec
- Stars
- 3.1k
- Forks
- 5.9k
- Avg merge
- 3d 2h
- Merged PRs (30d)
- 424
Description
Per suggestion: https://github.com/Azure/azure-rest-api-specs/discussions/41357#discussioncomment-16170166
### Option 2: Script-based bulk deletion
Use the GitHub CLI to delete stale branches in bulk:
> ⚠️ **WARNING**: Review the list before deleting!
```bash
# List all branches with their last commit date, filter old ones
# First, list all unprotected branches
gh api repos/Azure/azure-rest-api-specs-pr/branches --paginate \
--jq '.[] | select(.protected == false) | .name' > branches.txt
# For each branch, check if it was a head branch of a merged PR
while read branch; do
# Check for merged PRs using this branch
result=$(gh api "repos/Azure/azure-rest-api-specs-pr/pulls?head=Azure:${branch}&state=closed" \
--jq '[.[] | select(.merged_at != null)] | length')
if [ "$result" -gt "0" ]; then
echo "Can delete: $branch"
# Uncomment the next line to actually delete:
# gh api -X DELETE "repos/Azure/azure-rest-api-specs-pr/git/refs/heads/${branch}"
fi
done < branches.txt
```
Contributor guide
Assessment
This issue has not been assessed yet.