-
Notifications
You must be signed in to change notification settings - Fork 0
50 lines (42 loc) · 1.61 KB
/
pr-watcher.yaml
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
47
48
49
50
name: PR Watcher
on:
pull_request:
types: [opened, synchronize]
permissions:
contents: read
pull-requests: write
jobs:
check-pr-size:
runs-on: ubuntu-latest
steps:
- uses: actions/github-script@v7
env:
MAX_PR_SIZE: 500
with:
script: |
const MAX_PR_SIZE = parseInt(process.env.MAX_PR_SIZE);
const pr = context.payload.pull_request;
const exludeExtensions = ['.yaml', '.md', '.txt'];
const changedFiles = await github.rest.pulls.listFiles({
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: pr.number
});
const filteredFiles = changedFiles.data.filter(file => {
return !exludeExtensions.some(ext => file.filename.endsWith(ext));
});
const totalAdditions = changedFiles.data.reduce((acc, file) => {
if (!filteredFiles.includes(file.filename))
return acc + file.additions;
return 0;
}, 0);
core.notice(`Total additions: ${totalAdditions}`);
if (totalAdditions > MAX_PR_SIZE) {
github.rest.issues.createComment({
issue_number: pr.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: `:x: PR size is too large. Please keep PR size under ${MAX_PR_SIZE} additions.`
});
core.setFailed(`PR size is too large. Please keep PR size under ${MAX_PR_SIZE} additions.`);
} else { core.notice(`PR size is within limits.`); }