-
-
Notifications
You must be signed in to change notification settings - Fork 0
28 lines (25 loc) · 777 Bytes
/
prune-branches.yml
File metadata and controls
28 lines (25 loc) · 777 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
name: Nightly prune merged PR branches
on:
schedule:
- cron: '30 3 * * *'
workflow_dispatch:
permissions:
contents: write
pull-requests: read
jobs:
prune:
runs-on: ubuntu-latest
steps:
- name: Delete merged PR branches (keep main & gnome43-44)
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
REPO: ${{ github.repository }}
run: |
set -e
KEEP=" main gnome43-44 "
mapfile -t heads < <(gh pr list --state merged --limit 500 -R "$REPO" --json headRefName --jq '.[].headRefName')
for b in "${heads[@]}"; do
if [[ "$KEEP" == *" $b "* ]]; then continue; fi
echo "Deleting $b"
gh api -X DELETE repos/$REPO/git/refs/heads/$b || true
done