Close old issues #586
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 old issues | |
| on: | |
| workflow_dispatch: | |
| schedule: | |
| - cron: 40 17 */1 * * | |
| permissions: | |
| contents: read | |
| jobs: | |
| close-old-issues: | |
| runs-on: ubuntu-latest | |
| permissions: | |
| issues: write | |
| steps: | |
| - uses: actions/checkout@v6 | |
| with: | |
| persist-credentials: false | |
| - name: List open issues | |
| shell: bash | |
| run: | | |
| set -euo pipefail | |
| gh issue list --state open --search '-label:immortal' --json number,title | jq -c '.[]' >issues.txt | |
| env: | |
| GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Close issues with merged PRs | |
| run: | | |
| set -euo pipefail | |
| while read -r line; do | |
| issue=$(jq '.number' -r <<<"$line") | |
| title=$(jq '.title' -r <<<"$line") | |
| pr=$(sed -E 's/.*#([[:digit:]]+).*/\1/g' <<<"$title") | |
| re='^[0-9]+$' | |
| if ! [[ "$pr" =~ $re ]]; then | |
| continue; | |
| fi | |
| status=$( | |
| GH_TOKEN="${GH_TOKEN_PUBLIC}" gh --repo python/mypy pr view "$pr" --json state | jq '.state' -r \ | |
| || echo "unknown" | |
| ) | |
| if [[ $status = "MERGED" ]]; then | |
| gh issue close "$issue" --reason completed | |
| elif [[ $status = "unknown" ]]; then | |
| gh issue close "$issue" --reason "not planned" | |
| fi | |
| done <issues.txt | |
| env: | |
| GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| GH_TOKEN_PUBLIC: ${{ secrets.CUSTOM_GITHUB_PAT }} |