Close Empty PRs #236
This file contains 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 Empty PRs | |
on: | |
schedule: | |
- cron: '0 */6 * * *' # Runs every 6 hours | |
jobs: | |
close-empty-prs: | |
runs-on: ubuntu-24.04 | |
permissions: | |
pull-requests: write | |
steps: | |
- name: Check and close empty PRs | |
uses: actions/github-script@v7 | |
with: | |
script: | | |
const prs = await github.rest.pulls.list({ | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
state: 'open' | |
}); | |
for (const pr of prs.data) { | |
const files = await github.rest.pulls.listFiles({ | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
pull_number: pr.number | |
}); | |
if (files.data.length === 0) { | |
await github.rest.issues.createComment({ | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
issue_number: pr.number, | |
body: 'This PR is being closed automatically because it contains no changes.' | |
}); | |
await github.rest.pulls.update({ | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
pull_number: pr.number, | |
state: 'closed' | |
}); | |
} | |
} |