-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathcommitlint.config.cjs
More file actions
57 lines (48 loc) · 1.28 KB
/
commitlint.config.cjs
File metadata and controls
57 lines (48 loc) · 1.28 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
const fs = require('fs');
const commitMsgFilePath = process.argv[2];
const commitMessage = fs.readFileSync(commitMsgFilePath, 'utf8').trim();
const allowedTypes = [
'feat',
'fix',
'bug',
'refactor',
'design',
'style',
'docs',
'test',
'settings',
'chore',
'init',
'rename',
'remove',
'build',
'deploy',
'merge', // 소문자 merge도 허용
'Merge', // 대문자 Merge도 허용
];
const mergeCommitRegex = /^(merge|Merge)\s.+$/; // Merge로 시작하는 문장 전체 허용
const colonFormatRegex = /^(\w+):\s{1,2}(.+)$/; // type: message 형식
if (mergeCommitRegex.test(commitMessage)) {
// Merge 커밋은 무조건 통과
console.log('✅ Merge 커밋 - 통과');
process.exit(0);
}
const match = commitMessage.match(colonFormatRegex);
if (!match) {
console.error(`
❌ 커밋 실패 !
❗ 커밋 메시지는 "type: message" 형식이어야 하며, type과 message 사이에는 콜론(:)과 공백이 있어야 합니다.
예시: "feat: 로그인 기능 추가"
`);
process.exit(1);
}
const type = match[1];
if (!allowedTypes.includes(type)) {
console.error(`
❌ 커밋 실패 !
❗ "${type}"는 허용되지 않은 커밋 타입입니다.
허용 타입: ${allowedTypes.join(', ')}
`);
process.exit(1);
}
console.log('✅ 커밋 성공 !');