verify-commit-msg.js 988 B

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