Close stale PRs #57
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Close stale PRs | |
| on: | |
| schedule: | |
| - cron: "0 0 * * *" | |
| workflow_dispatch: | |
| env: | |
| GH_TOKEN: ${{ github.token }} | |
| jobs: | |
| check_stale_prs: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v4 | |
| - name: Close PRs | |
| run: | | |
| awaiting_labels=$(gh label list --json name --jq '.[] | select(.name | test("^S-awaiting")) | .name') | |
| date=$(date --date='10 days ago' --utc +%Y-%m-%dT%H:%M:%SZ) | |
| prs="" | |
| for label in $awaiting_labels; do | |
| pr_numbers=$( | |
| gh api /repos/${{ github.repository }}/pulls --jq '.[] | select ((.labels | any(.name == "'$label'")) and .head.repo.pushed_at < "'$date'") | .number') | |
| prs="$prs $pr_numbers" | |
| done | |
| for number in $prs; do | |
| # Check if the PR is still open | |
| if [ $(gh api /repos/${{ github.repository }}/pulls/$number --jq '.state') != "open" ]; then | |
| continue | |
| fi | |
| gh pr comment $number --body "This PR has been awaiting action for \ | |
| more than 10 days with no response. Because of this inactivity, the PR \ | |
| is being closed. If you continue working on the PR, please comment here \ | |
| when it is ready for re-review." | |
| gh pr close $number | |
| done |