verifyCommit.js 1014 B

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