diff --git a/docs/How_to_contribute.md b/docs/How_to_contribute.md index fdca00cf5..8972041c0 100644 --- a/docs/How_to_contribute.md +++ b/docs/How_to_contribute.md @@ -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: +``` +(scope)[optional info]: commit message +``` +where `` 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: diff --git a/scripts/dev/check-commit-msg.py b/scripts/dev/check-commit-msg.py new file mode 100644 index 000000000..f718c1123 --- /dev/null +++ b/scripts/dev/check-commit-msg.py @@ -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(scope)[optional info]: commit message") + print("where `` can be any of `feat,fix,test,chore,wip`.") + sys.exit(1)