verify-commit-msg.js 968 B

12345678910111213141516171819
  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(' See https://github.com/vuejs/vue/blob/dev/.github/COMMIT_CONVENTION.md for more details.\n')
  13. }${chalk.red(` You can also use ${chalk.cyan('npm run commit')} to interactively generate a commit message.\n`)}`,
  14. );
  15. process.exit(1);
  16. }