-
Notifications
You must be signed in to change notification settings - Fork 753
156 lines (144 loc) · 4.98 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
name: "PR Assistant"
on:
pull_request_target:
types:
- opened
- reopened
- synchronize
- edited
- ready_for_review
- converted_to_draft
merge_group:
permissions:
pull-requests: write
contents: read
jobs:
title:
runs-on: ubuntu-latest
steps:
- name: Check PR title if not sematic
uses: actions/github-script@v6
id: check
with:
script: |
if (!context.payload.pull_request) {
core.info('PR payload is null');
core.setOutput('title', 'ignore');
return;
}
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.error('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: 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: 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@v6
id: check
with:
script: |
if (!context.payload.pull_request) {
core.info('PR payload is null');
core.setOutput('cla', 'ignore');
return;
}
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.error('CLA is not signed');
core.setOutput('cla', 'not-signed');
} else {
core.setOutput('cla', 'signed');
}
- name: Delete Comment
if: 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: 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/doc/contributing/good-pr) 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
```