-
Notifications
You must be signed in to change notification settings - Fork 753
224 lines (211 loc) · 7.74 KB
/
pr.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
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
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
name: "PR Assistant"
on:
pull_request_target:
types:
- opened
- reopened
- synchronize
- edited
- ready_for_review
- converted_to_draft
permissions:
pull-requests: write
contents: read
jobs:
title:
runs-on: ubuntu-latest
steps:
- name: Check PR title if not sematic
uses: actions/github-script@v7
id: check
with:
script: |
const title = context.payload.pull_request.title;
const regex = /^(rfc|feat|fix|refactor|ci|docs|chore)(\([a-z0-9-]+\))?:/;
const m = title.match(regex);
if (!m) {
core.setFailed('PR title is not semantic');
core.setOutput('title', 'not-semantic');
return;
}
const prType = m[1];
const prScope = m[2];
const prSummary = title.substring(m[0].length);
let label = '';
switch (prType) {
case 'rfc':
label = 'pr-rfc';
break;
case 'feat':
label = 'pr-feature';
break;
case 'fix':
label = 'pr-bugfix';
break;
case 'refactor':
label = 'pr-refactor';
break;
case 'ci':
label = 'pr-build';
break;
case 'docs':
label = 'pr-doc';
break;
case 'chore':
label = 'pr-chore';
break;
}
const labels = await github.rest.issues.addLabels({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
labels: [label],
});
core.setOutput('title', 'semantic');
- name: Delete Comment
if: always() && steps.check.outputs.title == 'semantic'
uses: everpcpc/comment-on-pr-action@v1
with:
token: ${{ github.token }}
identifier: 'pr-assistant-title'
delete: true
- name: Comment on PR
if: always() && steps.check.outputs.title == 'not-semantic'
uses: everpcpc/comment-on-pr-action@v1
with:
token: ${{ github.token }}
identifier: 'pr-assistant-title'
body: |
This pull request's title is not fulfill the requirements. @${{ github.event.pull_request.user.login }} please update it 🙏.
Valid format:
```
fix(query): fix group by string bug
^ ^---------------------^
| |
| +-> Summary in present tense.
|
+-------> Type: rfc, feat, fix, refactor, ci, docs, chore
```
Valid types:
- `rfc`: this PR proposes a new RFC
- `feat`: this PR introduces a new feature to the codebase
- `fix`: this PR patches a bug in codebase
- `refactor`: this PR changes the code base without new features or bugfix
- `ci`: this PR changes build/testing/ci steps
- `docs`: this PR changes the documents or websites
- `chore`: this PR only has small changes that no need to record
cla:
runs-on: ubuntu-latest
steps:
- name: Check CLA if not signed
uses: actions/github-script@v7
id: check
with:
script: |
const body = context.payload.pull_request.body;
const regex = /I hereby agree to the terms of the CLA available at: https:\/\/docs.databend.com\/dev\/policies\/cla\//;
if (!regex.test(body)) {
core.setFailed('CLA is not signed');
core.setOutput('cla', 'not-signed');
} else {
core.setOutput('cla', 'signed');
}
- name: Delete Comment
if: always() && steps.check.outputs.cla == 'signed'
uses: everpcpc/comment-on-pr-action@v1
with:
token: ${{ github.token }}
identifier: 'pr-assistant-cla'
delete: true
- name: Comment on PR
if: always() && steps.check.outputs.cla == 'not-signed'
uses: everpcpc/comment-on-pr-action@v1
with:
token: ${{ github.token }}
identifier: 'pr-assistant-cla'
body: |
Pull request description must contain [CLA](https://docs.databend.com/dev/policies/cla/) like the following:
```
I hereby agree to the terms of the CLA available at: https://docs.databend.com/dev/policies/cla/
## Summary
Summary about this PR
- Close #issue
```
description:
runs-on: ubuntu-latest
steps:
- name: Check PR description checkbox
uses: actions/github-script@v7
id: check
with:
script: |
const body = context.payload.pull_request.body;
let section = "summary";
let testsChecked = false;
let changesChecked = false;
for (const line of body.split('\n')) {
if (line.includes("## Tests")) {
section = "tests";
core.info('checking section: tests');
continue;
} else if (line.includes("## Type of change")) {
section = "changes";
core.info('checking section: changes');
continue;
}
if (section === "tests") {
if (line.startsWith("- [x] ")) {
testsChecked = true;
core.info(`tests checked: ${line}`);
core.setOutput('tests', 'checked');
continue;
}
} else if (section === "changes") {
if (line.startsWith("- [x] ")) {
changesChecked = true;
core.info(`type of change checked: ${line}`);
core.setOutput('changes', 'checked');
continue;
}
}
}
if (!testsChecked) {
core.setOutput('tests', 'not-checked');
core.setFailed('Tests are not checked');
}
if (!changesChecked) {
core.setOutput('changes', 'not-checked');
core.setFailed('Type of Changes are not checked');
}
- name: Delete Comment for Tests
if: always() && steps.check.outputs.tests == 'checked'
uses: everpcpc/comment-on-pr-action@v1
with:
token: ${{ github.token }}
identifier: 'pr-assistant-description-tests'
delete: true
- name: Delete Comment for Changes
if: always() && steps.check.outputs.changes == 'checked'
uses: everpcpc/comment-on-pr-action@v1
with:
token: ${{ github.token }}
identifier: 'pr-assistant-description-changes'
delete: true
- name: Comment on PR for Tests
if: always() && steps.check.outputs.tests != 'checked'
uses: everpcpc/comment-on-pr-action@v1
with:
token: ${{ github.token }}
identifier: 'pr-assistant-description-tests'
body: |
At least one test kind must be checked in the PR description.
@${{ github.event.pull_request.user.login }} please update it 🙏.
- name: Comment on PR for Changes
if: always() && steps.check.outputs.changes != 'checked'
uses: everpcpc/comment-on-pr-action@v1
with:
token: ${{ github.token }}
identifier: 'pr-assistant-description-changes'
body: |
At least one type of change must be checked in the PR description.
@${{ github.event.pull_request.user.login }} please update it 🙏.