aboutsummaryrefslogtreecommitdiff
path: root/scripts/verifyCommit.ts
diff options
context:
space:
mode:
authorShinigami92 <[email protected]>2022-01-10 17:50:52 +0100
committerDaniel Bannert <[email protected]>2022-01-11 22:36:12 +0100
commit78dc2caa69d76665eaa22fc4ff16b2579a1ee827 (patch)
treeea0546b35fc39c0b2cfc6f703ebf70507540dcb1 /scripts/verifyCommit.ts
parentd4c295f698ed256cb6c53ea77249e64b544ca8c0 (diff)
downloadfaker-78dc2caa69d76665eaa22fc4ff16b2579a1ee827.tar.xz
faker-78dc2caa69d76665eaa22fc4ff16b2579a1ee827.zip
chore(ci): add commit automation
Diffstat (limited to 'scripts/verifyCommit.ts')
-rw-r--r--scripts/verifyCommit.ts28
1 files changed, 28 insertions, 0 deletions
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);
+}