Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Commit msg hook #409

Merged
merged 2 commits into from
Sep 27, 2023
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
12 changes: 12 additions & 0 deletions docs/How_to_contribute.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,18 @@ In general it is sufficient to follow the general installation instructions. How
- The `-e` switch ensures that changes in the python source code are immediately active.
- `[dev]` also installs some development requirements (e.g. mypy, black, pre-commit).
- Install some git hooks by running `pre-commit install` from the main directory of this project. These hooks help to ensure a good quality of the commited code by automatically running the black **formatter** and checking for **type safety** with mypy on every commit.
- Activate the git `commit-msg` hook to validate commit message formatting by creating a file named `.git/hooks/commit-msg` with the following contents:
```
#!/bin/sh
python scripts/dev/check-commit-msg.py $1
```

## Commit messages
Commit messages should follow the following format:
```
<type>(scope)[optional info]: commit message
```
where `<type>` can be any of `feat,fix,test,chore,wip`.

## Creating a new release
Execute the following steps in order to create a new DiscoPoP release:
Expand Down
34 changes: 34 additions & 0 deletions scripts/dev/check-commit-msg.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# This file is part of the DiscoPoP software (http://www.discopop.tu-darmstadt.de)
#
# Copyright (c) 2020, Technische Universitaet Darmstadt, Germany
#
# This software may be modified and distributed under the terms of
# the 3-Clause BSD License. See the LICENSE file in the package base
# directory for details.

# checks the commit message for correct formatting.
# invoked by the git commit-msg hook, if configured.
import sys
import re

# todo translate to python

path_to_commit_msg = sys.argv[1]

with open(path_to_commit_msg, "r") as f:
commit_msg = f.read()
commit_msg = commit_msg.replace("\n", "")

pattern = re.compile("^(feat|fix|test|chore|wip)(\(.+\))?(\[.+\])?:.+$")
matches = bool(pattern.match(commit_msg))

if matches:
print("VALID commit message: ", commit_msg)
sys.exit(0)
else:
print("INVALID commit message: ")
print("\t", commit_msg)
print("Please use the following format:")
print("\t<type>(scope)[optional info]: commit message")
print("where `<type>` can be any of `feat,fix,test,chore,wip`.")
sys.exit(1)