Skip to content

Commit 4a7062d

Browse files
authored
Merge pull request #99 from ioet/feature/enforce-commit-message-style#78
Feature/enforce commit message style. Close #78
2 parents fe27bbb + 7d33883 commit 4a7062d

File tree

4 files changed

+53
-1
lines changed

4 files changed

+53
-1
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]

README.md

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,9 @@ automatically [pip](https://pip.pypa.io/en/stable/) as well.
4646
4747
4848
Remember to do it with Python 3.
49-
49+
50+
- Run `pre-commit install`. For more details, check out Development > Git hooks.
51+
5052
### How to use it
5153
- Set the env var `FLASK_APP` to `time_tracker_api` and start the app:
5254
@@ -74,6 +76,16 @@ DateTime strings in Azure Cosmos DB is `YYYY-MM-DDThh:mm:ss.fffffffZ` which foll
7476
7577
## Development
7678
79+
### Git hooks
80+
We use [pre-commit](https://github.com/pre-commit/pre-commit) library to manage local git hooks, as developers we just need to run in our virtual environment:
81+
82+
```
83+
pre-commit install
84+
```
85+
With this command the library will take configuration from `.pre-commit-config.yaml` and will set up the hooks by us.
86+
87+
Currently, we only have a hook to enforce semantic commit message.
88+
7789
### Test
7890
We are using [Pytest](https://docs.pytest.org/en/latest/index.html) for tests. The tests are located in the package
7991
`tests` and use the [conventions for python test discovery](https://docs.pytest.org/en/latest/goodpractices.html#test-discovery).
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)