|
1 | | -name: "Manage Stale Issues, PRs & Unmerged Branches" |
2 | | - |
| 1 | +name: 'Close stale issues and PRs' |
3 | 2 | on: |
4 | 3 | schedule: |
5 | | - - cron: '30 1 * * *' # Runs daily at 1:30 AM UTC |
6 | | - workflow_dispatch: # Allows manual triggering |
| 4 | + - cron: '30 1 * * *' |
7 | 5 |
|
8 | 6 | permissions: |
9 | 7 | contents: write |
|
14 | 12 | stale: |
15 | 13 | runs-on: ubuntu-latest |
16 | 14 | steps: |
17 | | - - name: Mark Stale Issues and PRs |
18 | | - uses: actions/stale@v9 |
| 15 | + - uses: actions/stale@v9 |
19 | 16 | with: |
20 | | - stale-issue-message: "This issue is stale because it has been open 180 days with no activity. Remove stale label or comment, or it will be closed in 30 days." |
21 | | - stale-pr-message: "This PR is stale because it has been open 180 days with no activity. Please update or it will be closed in 30 days." |
| 17 | + stale-issue-message: 'This issue is stale because it has been open 180 days with no activity. Remove stale label or comment or this will be closed in 30 days.' |
22 | 18 | days-before-stale: 180 |
23 | 19 | days-before-close: 30 |
24 | | - exempt-issue-labels: "keep" |
25 | | - exempt-pr-labels: "keep" |
26 | | - |
27 | | - cleanup-branches: |
28 | | - runs-on: ubuntu-latest |
29 | | - steps: |
30 | | - - name: Checkout Repository |
31 | | - uses: actions/checkout@v4 |
32 | | - with: |
33 | | - fetch-depth: 0 # Fetch full history for accurate branch checks |
34 | | - |
35 | | - - name: Fetch All Branches |
36 | | - run: git fetch --all --prune |
37 | | - |
38 | | - - name: Delete Merged Branches With No Activity in Last 3 Months |
39 | | - run: | |
40 | | - echo "Checking merged branches with no activity in the last 3 months..." |
41 | | - for branch in $(git for-each-ref --format '%(refname:short) %(committerdate:unix)' refs/remotes/origin | awk -v date=$(date -d '3 months ago' +%s) '$2 < date {print $1}'); do |
42 | | - if [[ "$branch" != "origin/main" && "$branch" != "origin/dev" ]]; then |
43 | | - branch_name=${branch#origin/} |
44 | | - echo "Deleting inactive merged branch: $branch_name" |
45 | | - git push origin --delete "$branch_name" |
46 | | - fi |
47 | | - done |
48 | | -
|
49 | | - - name: Delete PR Approved and Merged Branches Older Than 30 Days |
50 | | - run: | |
51 | | - echo "Checking branches with PRs approved and merged into main or dev for 30+ days..." |
52 | | - for branch in $(gh api repos/${{ github.repository }}/pulls --jq '.[] | select(.merged_at != null and (.base.ref == "main" or .base.ref == "dev")) | select(.merged_at | fromdateiso8601 < (now - 2592000)) | .head.ref'); do |
53 | | - echo "Deleting merged PR branch: $branch" |
54 | | - git push origin --delete "$branch" |
55 | | - done |
56 | | - env: |
57 | | - GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
0 commit comments