-
Notifications
You must be signed in to change notification settings - Fork 0
46 lines (40 loc) · 1.32 KB
/
close-empty-prs.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
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'
});
}
}