Skip to content

Commit 4b8167f

Browse files
author
Atiqur Rahman
committed
feat: add conventional-pre-commit file
1 parent 9aaaab3 commit 4b8167f

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

detekt.gradle

+12
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,15 @@ task createDetektPreCommitHook() {
1717
"""
1818
"chmod +x .git/hooks/pre-commit".execute()
1919
}
20+
21+
task createConventionalMessagePreCommitHook() {
22+
def gitHooksDirectory = new File("$project.rootDir/.git/hooks/")
23+
if (!gitHooksDirectory.exists()) gitHooksDirectory.mkdirs()
24+
new File("$project.rootDir/.git/hooks", "commit-msg").text = """
25+
#!/bin/bash
26+
echo "Running Conventional Commit check"
27+
commit_message="\$1"
28+
./scripts/conventional-pre-commit.sh "\$commit_message"
29+
"""
30+
"chmod +x .git/hooks/commit-msg".execute()
31+
}

scripts/conventional-pre-commit.sh

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#!/usr/bin/env bash
2+
3+
if ! grep -qE "^\bbuild\b|\bchore\b|\bci\b|\bdocs\b|\bfeat\b|\bfix\b|\bperf\b|\brefactor\b|\brevert\b|\bstyle\b|\btest\b(\([a-z ]+\)!)?: [\w ]+$" "$1"; then
4+
cat $1
5+
echo "
6+
Your commit message doesn't conform to Convential Commit Rules (https://www.conventionalcommits.org/).
7+
At a minimum, your commit should start with one of the below keywords:
8+
build: chore: ci: docs: feat: fix: perf: refactor: revert: style: test:
9+
Example commit message to add a feature: 'feat: Changed something to add a lovely new feature'
10+
Example commit message to fix an issue: 'fix: Removed infinite loop causing that annoying bug'
11+
"
12+
exit 1
13+
fi

0 commit comments

Comments
 (0)