forked from higress-group/himarket
-
Notifications
You must be signed in to change notification settings - Fork 0
193 lines (168 loc) · 6.85 KB
/
pr-check.yml
File metadata and controls
193 lines (168 loc) · 6.85 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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
name: PR Check
on:
pull_request:
types: [opened, edited, synchronize, reopened]
jobs:
pr-title-check:
name: PR Title Check
runs-on: ubuntu-latest
steps:
- name: Check PR Title
uses: amannn/action-semantic-pull-request@v5
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
# Allowed types
types: |
feat
fix
docs
style
refactor
perf
test
build
ci
chore
revert
# Scope is optional
requireScope: false
# Subject must start with lowercase letter
subjectPattern: ^(?![A-Z]).+$
subjectPatternError: |
PR title format is incorrect!
❌ Wrong examples:
- feat: Add new feature (first letter should be lowercase)
- add new feature (missing type prefix)
- featadd new feature (missing colon and space)
✅ Correct format:
type: brief description
or
type(scope): brief description
Allowed types:
- feat: new feature
- fix: bug fix
- docs: documentation update
- style: code formatting
- refactor: code refactoring
- perf: performance improvement
- test: testing
- build: build system
- ci: CI/CD
- chore: other changes
- revert: revert previous commit
Examples:
✅ feat: add product feature configuration
✅ fix: fix product list pagination
✅ feat(product): add feature configuration
✅ docs: update README deployment guide
pr-content-check:
name: PR Content Check
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Check PR Description
uses: actions/github-script@v7
with:
script: |
const pr = context.payload.pull_request;
const body = pr.body || '';
console.log('PR Body:', body);
// Required checks
const checks = {
hasDescription: {
test: () => {
const descSection = body.match(/##\s*Description\s*([\s\S]*?)(?=##|$)/i);
if (!descSection) return false;
const content = descSection[1].replace(/<!--[\s\S]*?-->/g, '').trim();
return content.length > 10;
},
message: '❌ Missing description or too short (at least 10 characters required)'
},
hasCodeFormatted: {
test: () => {
const checklistSection = body.match(/##\s*Checklist\s*([\s\S]*?)(?=##|$)/i);
if (!checklistSection) return false;
// Check if "Code has been formatted" is checked
return /- \[x\].*mvn spotless:apply/i.test(checklistSection[1]);
},
message: '❌ Please confirm code has been formatted with `mvn spotless:apply`'
}
};
// Execute checks
const errors = [];
const warnings = [];
for (const [key, check] of Object.entries(checks)) {
if (!check.test()) {
errors.push(check.message);
}
}
// Optional checks (warnings only)
const hasIssueLink = /(?:close[sd]?|fix(?:e[sd])?|resolve[sd]?)\s+#\d+/i.test(body);
if (!hasIssueLink) {
warnings.push('⚠️ Consider linking related issues (e.g., `Fix #123` or `Close #456`)');
}
if (body.length < 50) {
warnings.push('⚠️ PR description is short. Consider adding more details.');
}
// Generate report
let comment = '## PR Content Check Report\n\n';
if (errors.length === 0) {
comment += '### ✅ All required checks passed\n\n';
} else {
comment += '### ❌ Required items need to be completed\n\n';
errors.forEach(error => {
comment += `${error}\n`;
});
comment += '\n';
}
if (warnings.length > 0) {
comment += '### 💡 Suggestions\n\n';
warnings.forEach(warning => {
comment += `${warning}\n`;
});
comment += '\n';
}
comment += '---\n\n';
comment += '**PR Content Requirements:**\n\n';
comment += '**Required:**\n';
comment += '- **Description**: Clear explanation of changes (minimum 10 characters)\n';
comment += '- **Code Formatting**: Check the box in Checklist (Note: Code format is automatically verified by CI)\n\n';
comment += '**Optional but recommended:**\n';
comment += '- **Related Issues**: Link issues using `Fix #123`, `Close #456`, or `Resolve #789`\n';
comment += '- **Other Checklist Items**: Self-review, tests, documentation, etc.\n\n';
comment += 'Example format:\n';
comment += '```markdown\n';
comment += '## Description\n\n';
comment += '- Refactor client initialization method\n';
comment += '- Optimize parameter handling\n\n';
comment += '## Related Issues\n\n';
comment += 'Fix #123\n\n';
comment += '## Checklist\n\n';
comment += '- [x] Code has been formatted with `mvn spotless:apply`\n';
comment += '- [x] Code is self-reviewed\n';
comment += '```\n';
// Output to Job Summary (visible in PR checks)
await core.summary
.addRaw(comment)
.write();
// Output to console
console.log('\n' + comment);
// Create annotations for errors and warnings
errors.forEach(error => {
core.error(error.replace(/❌\s*/, ''), {
title: 'PR Content Check Failed',
file: '.github/PULL_REQUEST_TEMPLATE.md'
});
});
warnings.forEach(warning => {
core.warning(warning.replace(/⚠️\s*/, ''), {
title: 'PR Content Suggestion',
file: '.github/PULL_REQUEST_TEMPLATE.md'
});
});
// Fail if there are errors
if (errors.length > 0) {
core.setFailed(`PR content check failed: ${errors.length} required item(s) incomplete`);
}