Skip to content

Commit 3f9cc6f

Browse files
Merge pull request #150 from elliottmurray/style/git_message
ci: add check for commit messages
2 parents 304c578 + e1cb5b6 commit 3f9cc6f

File tree

3 files changed

+54
-0
lines changed

3 files changed

+54
-0
lines changed

.travis.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ rvm: "2.2"
1313

1414
sudo: false
1515

16+
before_install:
17+
- script/commit_message.py
18+
1619
install:
1720
- pip install -r requirements_dev.txt
1821

CONTRIBUTING.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,19 @@ We also appreciate it if you take the time to update and write tests for any cha
2525
you submit.
2626

2727
[e2e]: https://github.com/pact-foundation/pact-python/tree/master/e2e
28+
29+
## Commit messages
30+
Pact Python is adopting the Conventional Changelog commit message conventions. Please ensure you follow the guidelines, we don't want to be that person, but the commit messages are very important to the automation of our release process.
31+
32+
Take a look at the git history (git log) to get the gist of it.
33+
34+
If you'd like to get some CLI assistance there is a node npm package. Example usage is:
35+
36+
```
37+
npm install commitizen -g
38+
npm i -g cz-conventional-changelog
39+
```
40+
41+
git cz to commit and commitizen will guide you.
42+
43+
There is a pypi package that does similar [commitizen]: https://pypi.org/project/commitizen/. This would make a great feature to add! There is a check on the travis build that your commits follow this convention. On creating a PR any commits that don't will instantly fail the build and you will have to rename them.

script/commit_message.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
#!/usr/bin/env python
2+
import re
3+
import sys
4+
import subprocess
5+
6+
examples = """+ 61c8ca9 fix: navbar not responsive on mobile
7+
+ 479c48b test: prepared test cases for user authentication
8+
+ a992020 chore: moved to semantic versioning
9+
+ b818120 fix: button click even handler firing twice
10+
+ c6e9a97 fix: login page css
11+
+ dfdc715 feat(auth): added social login using twitter
12+
"""
13+
14+
15+
def main():
16+
17+
cmd = "git log --pretty=format:'%s' master..HEAD"
18+
commits = subprocess.check_output(cmd, shell=True)
19+
commits = commits.decode("utf-8").split('\n')
20+
for commit in commits:
21+
22+
pattern = r'((build|ci|docs|feat|fix|perf|refactor|style|test|chore|revert)(\([\w\-]+\))?:\s.*)|((Merge)(\([\w\-]+\))?\s.*)' # noqa
23+
m = re.match(pattern, commit)
24+
if m is None:
25+
print("\nError with git message '{}' style".format(commit))
26+
print("\nPlease change commit message to the conventional format and try to commit again. Examples:") # noqa
27+
28+
print("\n" + examples)
29+
sys.exit(1)
30+
31+
print("Commit messages valid")
32+
33+
34+
if __name__ == "__main__":
35+
main()

0 commit comments

Comments
 (0)