-
Notifications
You must be signed in to change notification settings - Fork 0
59 lines (51 loc) · 1.96 KB
/
conventional-commits.yml
File metadata and controls
59 lines (51 loc) · 1.96 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
name: Conventional Commits
on:
pull_request:
branches: [ main ]
types: [ opened, edited, synchronize, reopened, ready_for_review ]
permissions:
contents: read
pull-requests: read
jobs:
validate:
name: Conventional Commits
runs-on: ubuntu-latest
steps:
- name: Validate PR title and commits
uses: actions/github-script@v9
with:
script: |
const allowed = /^(build|chore|ci|docs|feat|fix|perf|refactor|revert|style|test)(\([A-Za-z0-9._/-]+\))?!?: .+$/;
const allowedSpecial = /^(Merge .+|Revert ".+")$/;
const failures = [];
const title = context.payload.pull_request.title;
if (!allowed.test(title) && !allowedSpecial.test(title)) {
failures.push(`PR title: ${title}`);
}
const commits = await github.paginate(github.rest.pulls.listCommits, {
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: context.payload.pull_request.number,
per_page: 100,
});
for (const commit of commits) {
const subject = commit.commit.message.split('\n')[0];
if (!allowed.test(subject) && !allowedSpecial.test(subject)) {
failures.push(`${commit.sha.substring(0, 7)}: ${subject}`);
}
}
if (failures.length > 0) {
core.setFailed([
'Conventional Commit validation failed.',
'',
'Expected format:',
' type(scope): description',
' type: description',
'',
'Allowed types:',
' build, chore, ci, docs, feat, fix, perf, refactor, revert, style, test',
'',
'Failures:',
...failures.map(f => ` - ${f}`),
].join('\n'));
}