Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
chore: add pre-commit library and config to enforce semantic commit m…
…essages
  • Loading branch information
Angeluz-07 committed Apr 22, 2020
commit 9a951ae631036961a0c291649bf15975d3b33493
8 changes: 8 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
repos:
- repo: local
hooks:
- id: semantic-commit-msg
name: Check semantic commit message format
entry: python ./commons/git_hooks/enforce_semantic_commit_msg.py
language: python
stages : [commit-msg]
29 changes: 29 additions & 0 deletions commons/git_hooks/enforce_semantic_commit_msg.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import re
import sys

ERROR_MSG = """
Commit failed!
Please use semantic commit message format. Examples:
'feat: Applying some changes'
'fix: Fixing something broken'
'feat(config): Fix something in config files'

For more details in commit message format, review https://github.com/angular/angular.js/blob/master/DEVELOPERS.md#commits
"""

SUCCESS_MSG = "Commit succeed!. Semantic commit message is correct."

COMMIT_MSG_REGEX = r'(build|ci|docs|feat|fix|perf|refactor|style|test|chore|revert)(\([\w\-]+\))?:\s.*'


# Get the commit message file
commit_msg_file = open(sys.argv[1]) # The first argument is the file
commit_msg = commit_msg_file.read()


if re.match(COMMIT_MSG_REGEX, commit_msg) is None:
print(ERROR_MSG)
sys.exit(1)

print(SUCCESS_MSG)
sys.exit(0)
3 changes: 3 additions & 0 deletions requirements/time_tracker_api/dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,6 @@ pytest-mock==2.0.0

# Coverage
coverage==4.5.1

# Git hooks
pre-commit==2.2.0