Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
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]
14 changes: 13 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,9 @@ automatically [pip](https://pip.pypa.io/en/stable/) as well.


Remember to do it with Python 3.


- Run `pre-commit install`. For more details, check out Development > Git hooks.

### How to use it
- Set the env var `FLASK_APP` to `time_tracker_api` and start the app:

Expand Down Expand Up @@ -74,6 +76,16 @@ DateTime strings in Azure Cosmos DB is `YYYY-MM-DDThh:mm:ss.fffffffZ` which foll

## Development

### Git hooks
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's reference this section as a step in the Setup.

  • Run pre-commit install. For more details, check out Development > Git hooks.

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:

```
pre-commit install
```
With this command the library will take configuration from `.pre-commit-config.yaml` and will set up the hooks by us.

Currently, we only have a hook to enforce semantic commit message.

### Test
We are using [Pytest](https://docs.pytest.org/en/latest/index.html) for tests. The tests are located in the package
`tests` and use the [conventions for python test discovery](https://docs.pytest.org/en/latest/goodpractices.html#test-discovery).
Expand Down
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