From 78dc2caa69d76665eaa22fc4ff16b2579a1ee827 Mon Sep 17 00:00:00 2001 From: Shinigami92 Date: Mon, 10 Jan 2022 17:50:52 +0100 Subject: chore(ci): add commit automation --- scripts/verifyCommit.ts | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 scripts/verifyCommit.ts (limited to 'scripts/verifyCommit.ts') diff --git a/scripts/verifyCommit.ts b/scripts/verifyCommit.ts new file mode 100644 index 00000000..2584cc37 --- /dev/null +++ b/scripts/verifyCommit.ts @@ -0,0 +1,28 @@ +// Invoked on the commit-msg git hook by simple-git-hooks. + +import colors from 'picocolors'; +import { readFileSync } from 'fs'; + +// get $1 from commit-msg script +const msgPath = process.argv[2]; +const msg = readFileSync(msgPath, 'utf-8').trim(); + +const releaseRE = /^v\d/; +const commitRE = + /^(revert: )?(feat|fix|docs|dx|refactor|perf|test|workflow|build|ci|chore|types|wip|release|deps)(\(.+\))?: .{1,50}/; + +if (!releaseRE.test(msg) && !commitRE.test(msg)) { + console.log(); + console.error( + ` ${colors.bgRed(colors.white(' ERROR '))} ${colors.red( + `invalid commit message format.` + )}\n\n` + + colors.red( + ` Proper commit message format is required for automated changelog generation. Examples:\n\n` + ) + + ` ${colors.green(`feat: add 'comments' option`)}\n` + + ` ${colors.green(`fix: handle events on blur (close #28)`)}\n\n` + + colors.red(` See .github/commit-convention.md for more details.\n`) + ); + process.exit(1); +} -- cgit v1.2.3