123456789101112131415161718192021222324252627282930 |
- // Invoked on the commit-msg git hook by yorkie.
- const { bgRed, red, green, white } = require('kolorist');
- const fs = require('fs');
- const msgPath = process.env.GIT_PARAMS;
- const msg = fs.readFileSync(msgPath || './.git/COMMIT_EDITMSG', 'utf-8').trim();
- console.log('***********');
- console.log('commit msg:', msg);
- console.log('***********');
- const releaseRE = /^v\d/;
- const commitRE =
- /^(revert: )?(feat|fix|docs|dx|refactor|perf|test|workflow|build|ci|chore|types|wip|release|deps)(\(.+\))?: .{1,50}/;
- if (!releaseRE.test(msg) && !commitRE.test(msg)) {
- console.log();
- console.error(
- ` ${bgRed(white(' ERROR '))} ${red(
- `invalid commit message format.`
- )}\n\n${red(
- ` Proper commit message format is required for automated changelog generation. Examples:\n\n`
- )} ${green(`feat: add 'comments' option`)}\n` +
- ` ${green(`fix: handle events on blur (close #28)`)}\n\n${red(
- ` See commit-convention.md for more details.\n`
- )}`
- );
- process.exit(1);
- }
|