File tree Expand file tree Collapse file tree 1 file changed +26
-0
lines changed
Expand file tree Collapse file tree 1 file changed +26
-0
lines changed Original file line number Diff line number Diff line change 3939 gh pr close $pr_number
4040 fi
4141 done <<< "$prs"
42+
43+ - name : Delete stale branches
44+ env :
45+ GH_TOKEN : ${{ secrets.GITHUB_TOKEN }}
46+ run : |
47+ # Get all branches with patchwork-ci- prefix
48+ branches=$(gh api repos/${{ github.repository }}/branches --jq '.[] | select(.name | startswith("patchwork-ci-")) | "\(.name) \(.commit.commit.committer.date)"')
49+
50+ while IFS= read -r line; do
51+ if [ -z "$line" ]; then
52+ continue
53+ fi
54+
55+ branch_name=$(echo "$line" | awk '{print $1}')
56+ created_at=$(echo "$line" | awk '{print $2}')
57+
58+ # Convert to Unix timestamp
59+ created_ts=$(date -d "$created_at" +%s)
60+ current_ts=$(date +%s)
61+ age_days=$(( (current_ts - created_ts) / 86400 ))
62+
63+ if [ $age_days -gt 7 ]; then
64+ echo "Deleting branch $branch_name (age: $age_days days)"
65+ gh api -X DELETE repos/${{ github.repository }}/git/refs/heads/$branch_name
66+ fi
67+ done <<< "$branches"
You can’t perform that action at this time.
0 commit comments