Skip to content

Commit 9a951ae

Browse files
committed
chore: add pre-commit library and config to enforce semantic commit messages
1 parent fe27bbb commit 9a951ae

File tree

3 files changed

+40
-0
lines changed

3 files changed

+40
-0
lines changed

.pre-commit-config.yaml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
repos:
2+
- repo: local
3+
hooks:
4+
- id: semantic-commit-msg
5+
name: Check semantic commit message format
6+
entry: python ./commons/git_hooks/enforce_semantic_commit_msg.py
7+
language: python
8+
stages : [commit-msg]
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import re
2+
import sys
3+
4+
ERROR_MSG = """
5+
Commit failed!
6+
Please use semantic commit message format. Examples:
7+
'feat: Applying some changes'
8+
'fix: Fixing something broken'
9+
'feat(config): Fix something in config files'
10+
11+
For more details in commit message format, review https://github.com/angular/angular.js/blob/master/DEVELOPERS.md#commits
12+
"""
13+
14+
SUCCESS_MSG = "Commit succeed!. Semantic commit message is correct."
15+
16+
COMMIT_MSG_REGEX = r'(build|ci|docs|feat|fix|perf|refactor|style|test|chore|revert)(\([\w\-]+\))?:\s.*'
17+
18+
19+
# Get the commit message file
20+
commit_msg_file = open(sys.argv[1]) # The first argument is the file
21+
commit_msg = commit_msg_file.read()
22+
23+
24+
if re.match(COMMIT_MSG_REGEX, commit_msg) is None:
25+
print(ERROR_MSG)
26+
sys.exit(1)
27+
28+
print(SUCCESS_MSG)
29+
sys.exit(0)

requirements/time_tracker_api/dev.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,6 @@ pytest-mock==2.0.0
1313

1414
# Coverage
1515
coverage==4.5.1
16+
17+
# Git hooks
18+
pre-commit==2.2.0

0 commit comments

Comments
 (0)