Skip to content

Commit

Permalink
ci: add check for commit messages
Browse files Browse the repository at this point in the history
  • Loading branch information
elliottmurray committed Jun 26, 2020
1 parent 930a14a commit ca11232
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ rvm: "2.2"

sudo: false

before_install:
- script/commit_message.py

install:
- pip install -r requirements_dev.txt

Expand Down
34 changes: 34 additions & 0 deletions script/commit_message.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#!/usr/bin/env python
import re
import sys
import subprocess

examples = """+ 61c8ca9 fix: navbar not responsive on mobile
+ 479c48b test: prepared test cases for user authentication
+ a992020 chore: moved to semantic versioning
+ b818120 fix: button click even handler firing twice
+ c6e9a97 fix: login page css
+ dfdc715 feat(auth): added social login using twitter
"""


def main():

cmd = "git log --pretty=format:'%s' master..HEAD"
commits = subprocess.check_output(cmd, shell=True)
commits = commits.decode("utf-8").split('\n')
for commit in commits:
pattern = r'(build|ci|docs|feat|fix|perf|refactor|style|test|chore|revert)(\([\w\-]+\))?:\s.*' # noqa
m = re.match(pattern, commit)
if m is None:
print("\nError with git message '{}' style".format(commit))
print("\nPlease change commit message to the conventional format and try to commit again. Examples:") # noqa

print("\n" + examples)
sys.exit(1)

print("Commit messages valid")


if __name__ == "__main__":
main()

0 comments on commit ca11232

Please sign in to comment.