-
Notifications
You must be signed in to change notification settings - Fork 0
107 lines (91 loc) · 3.6 KB
/
pr-size.yml
File metadata and controls
107 lines (91 loc) · 3.6 KB
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
name: PR Size Check
on:
pull_request:
types: [opened, synchronize, reopened]
permissions:
pull-requests: write
contents: read
jobs:
check-size:
name: Check PR Size
runs-on: ubuntu-latest
if: github.event.pull_request.draft == false
steps:
- name: Check PR size
uses: actions/github-script@v8
with:
script: |
const pr = context.payload.pull_request;
const additions = pr.additions;
const deletions = pr.deletions;
const totalChanges = additions + deletions;
const thresholds = {
small: 100,
medium: 500,
large: 1000,
xl: 2000
};
let size = 'small';
let emoji = '✅';
let message = '';
if (totalChanges >= thresholds.xl) {
size = 'XL';
emoji = '🚨';
message = `This PR is **extremely large** (${totalChanges.toLocaleString()} changes). Please consider breaking it into multiple smaller PRs for easier review.`;
} else if (totalChanges >= thresholds.large) {
size = 'L';
emoji = '⚠️';
message = `This PR is **large** (${totalChanges.toLocaleString()} changes). Consider breaking it into smaller, focused PRs if possible.`;
} else if (totalChanges >= thresholds.medium) {
size = 'M';
emoji = '📦';
message = `This PR is **medium-sized** (${totalChanges.toLocaleString()} changes). Reviewers, please allocate sufficient time.`;
} else {
size = 'S';
emoji = '✅';
message = `This PR is **small** (${totalChanges.toLocaleString()} changes). Easy to review!`;
}
const comment = `## ${emoji} PR Size: ${size}
**Changes:** +${additions.toLocaleString()} / -${deletions.toLocaleString()} (${totalChanges.toLocaleString()} total)
${message}
---
*This check helps maintain code review quality. Smaller PRs are easier to review and merge faster.*`;
// Find existing bot comment
const comments = await github.rest.issues.listComments({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: pr.number,
});
const botComment = comments.data.find(
comment => comment.user.type === 'Bot' && comment.body.includes('PR Size:')
);
if (botComment) {
// Update existing comment
await github.rest.issues.updateComment({
owner: context.repo.owner,
repo: context.repo.repo,
comment_id: botComment.id,
body: comment,
});
} else {
// Create new comment
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: pr.number,
body: comment,
});
}
// Add label based on size
const labelName = `size/${size.toLowerCase()}`;
try {
await github.rest.issues.addLabels({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: pr.number,
labels: [labelName],
});
} catch (error) {
// Label might not exist, that's okay
console.log(`Label ${labelName} might not exist yet`);
}