-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(ci)[commit-msg hook]: automatic check of commit message formatting
- Loading branch information
1 parent
d570b15
commit 7082506
Showing
2 changed files
with
46 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)(\(\S+\))?(\[\S+\])?:.+$") | ||
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) |