verify-commit-msg.js 818 B

1234567891011121314151617
  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 = /^(revert: )?(feat|fix|polish|docs|style|refactor|perf|test|workflow|ci|chore|types|build)(\(.+\))?: .{1,50}/
  5. if (!commitRE.test(msg)) {
  6. console.log()
  7. console.error(
  8. ` ${chalk.bgRed.white(' ERROR ')} ${chalk.red(`invalid commit message format.`)}\n\n` +
  9. chalk.red(` Proper commit message format is required for automated changelog generation. Examples:\n\n`) +
  10. ` ${chalk.green(`feat(compiler): add 'comments' option`)}\n` +
  11. ` ${chalk.green(`fix(v-model): handle events on blur (close #28)`)}\n\n` +
  12. chalk.red(` You can also use ${chalk.cyan(`npm run commit`)} to interactively generate a commit message.\n`)
  13. )
  14. process.exit(1)
  15. }