-
Notifications
You must be signed in to change notification settings - Fork 235
Expand file tree
/
Copy pathverify-commit.js
More file actions
26 lines (23 loc) · 963 Bytes
/
Copy pathverify-commit.js
File metadata and controls
26 lines (23 loc) · 963 Bytes
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
import pico from 'picocolors';
import { readFileSync } from 'node:fs';
import { resolve } from 'node:path';
const msgPath = resolve('.git/COMMIT_EDITMSG');
const msg = readFileSync(msgPath, 'utf-8').trim();
const commitRE =
/^(Release v)|(Merge.*branch)|((revert: )?(feat|fix|docs|dx|style|refactor|perf|test|workflow|build|ci|chore|types|wip|release|version)(\(.+\))?: .+)/;
if (!commitRE.test(msg)) {
console.error(
`\n ${pico.white(pico.bgRed(' ERROR '))} ${pico.red(
`invalid commit message format.`,
)}\n\n` +
pico.red(
` Proper commit message format is required for automated changelog generation. Examples:\n\n`,
) +
` ${pico.green(`feat(av-canvas): add 'video-sprite' feature`)}\n` +
` ${pico.green(
`fix(event-tool): clear listeners on listener interface (close #00)`,
)}\n\n` +
pico.red(` See .github/commit-convention.md for more details.\n`),
);
process.exit(1);
}