forked from rad-ui/ui
-
Notifications
You must be signed in to change notification settings - Fork 0
64 lines (56 loc) · 2.04 KB
/
Copy pathpr-title.yml
File metadata and controls
64 lines (56 loc) · 2.04 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
name: PR Title
on:
pull_request_target:
types: [opened, edited, reopened, synchronize]
permissions:
contents: read
pull-requests: read
concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number }}
cancel-in-progress: true
jobs:
validate-title:
name: Validate PR title
runs-on: ubuntu-latest
steps:
- name: Validate title format
uses: actions/github-script@v8
with:
script: |
const title = context.payload.pull_request.title;
const pattern = /^(feat|fix|docs|refactor|perf|test|build|ci|chore|revert)(\([a-z0-9][a-z0-9-]*\))?: (.+)$/;
const match = title.match(pattern);
if (match) {
const summary = match[3];
const trimmed = summary.trim();
const startsLowercase = /^[a-z]/.test(trimmed);
const hasTrailingPeriod = trimmed.endsWith('.');
const withinLimit = title.length <= 72;
if (startsLowercase && !hasTrailingPeriod && withinLimit) {
core.info(`PR title is valid: "${title}"`);
return;
}
}
core.setFailed(
[
`Invalid PR title: "${title}"`,
'',
'Expected format:',
'type(scope): short summary',
'',
'Allowed types:',
'feat, fix, docs, refactor, perf, test, build, ci, chore, revert',
'',
'Examples:',
'- ci(docs): add next build check for docs changes',
'- fix(dialog): restore focus after nested close',
'- docs(installation): clarify pnpm-only docs setup',
'',
'Rules:',
'- scope is optional',
'- use lowercase type and scope',
'- summary should start lowercase',
'- no trailing period',
'- keep the full title under 72 characters'
].join('\n')
);