verifyCommit.js 1.0 KB

1234567891011121314151617181920212223242526272829303132
  1. // Invoked on the commit-msg git hook by yorkie.
  2. const chalk = require('chalk')
  3. const msgPath = process.env.GIT_PARAMS
  4. const msg = require('fs')
  5. .readFileSync(msgPath, 'utf-8')
  6. .trim()
  7. const commitRE = /^(revert: )?(feat|fix|docs|dx|style|refactor|perf|test|workflow|build|ci|chore|types|wip)(\(.+\))?: .{1,50}/
  8. if (!commitRE.test(msg)) {
  9. console.log()
  10. console.error(
  11. ` ${chalk.bgRed.white(' ERROR ')} ${chalk.red(
  12. `invalid commit message format.`
  13. )}\n\n` +
  14. chalk.red(
  15. ` Proper commit message format is required for automated changelog generation. Examples:\n\n`
  16. ) +
  17. ` ${chalk.green(`feat(compiler): add 'comments' option`)}\n` +
  18. ` ${chalk.green(
  19. `fix(v-model): handle events on blur (close #28)`
  20. )}\n\n` +
  21. chalk.red(` See .github/COMMIT_CONVENTION.md for more details.\n`) +
  22. chalk.red(
  23. ` You can also use ${chalk.cyan(
  24. `npm run commit`
  25. )} to interactively generate a commit message.\n`
  26. )
  27. )
  28. process.exit(1)
  29. }