Azure / Azure/azure-rest-api-specs

[EngSys] Cleanup stale branches from merged PRs

Open
#41,454 0 comments 0 reactions 1 assignee Claimed by @mikeharder View on GitHub
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

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.