forked from KelvinTegelaar/CIPP
-
Notifications
You must be signed in to change notification settings - Fork 0
65 lines (56 loc) · 2.33 KB
/
Copy pathConventional_Commits.yml
File metadata and controls
65 lines (56 loc) · 2.33 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
name: Conventional Commits Check
on:
# Using pull_request_target instead of pull_request for secure handling of fork PRs
pull_request_target:
# Re-run on title edits so a corrected title clears the check
types: [opened, synchronize, reopened, edited]
# Only check PRs targeting the dev branch
branches:
- dev
permissions:
pull-requests: write
issues: write
jobs:
conventional-commits:
name: Validate Conventional Commits
runs-on: ubuntu-slim
steps:
- name: Validate PR title
uses: actions/github-script@v9
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const title = context.payload.pull_request.title || '';
const pattern = /^(feat|fix|docs|style|refactor|perf|test|chore|ci|build|revert)(\(.+\))?!?: .+/i;
if (pattern.test(title)) {
console.log(`✓ PR title follows Conventional Commits format: "${title}"`);
return;
}
console.log(`❌ PR title does not follow Conventional Commits format: "${title}"`);
const message = [
'❌ **This PR title does not follow the [Conventional Commits](https://www.conventionalcommits.org/) format.**',
'',
'Expected format: `type(scope)?: description`',
'',
'Allowed types: `feat`, `fix`, `docs`, `style`, `refactor`, `perf`, `test`, `chore`, `ci`, `build`, `revert`',
'',
'Examples:',
'- `feat: add tenant filter to the user table`',
'- `fix(auth): handle expired refresh tokens`',
'- `docs: update self-hosting guide`',
'',
`Received: \`${title}\``,
'',
'🔒 This PR has been automatically closed. Please update the title to match the format above and reopen the PR.'
].join('\n');
await github.rest.issues.createComment({
...context.repo,
issue_number: context.issue.number,
body: message
});
await github.rest.pulls.update({
...context.repo,
pull_number: context.issue.number,
state: 'closed'
});
core.setFailed(`PR title does not follow Conventional Commits format: "${title}"`);