Advertisement
Guest User

Untitled

a guest
Apr 24th, 2019
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.19 KB | None | 0 0
  1. #!/usr/bin/env python
  2. import sys, os, re
  3. from subprocess import check_output
  4.  
  5. # Collect the parameters
  6. commit_msg_filepath = sys.argv[1]
  7.  
  8. # Figure out which branch we're on
  9. branch = check_output(['git', 'symbolic-ref', '--short', 'HEAD']).strip()
  10. print "commit-msg: On branch '%s'" % branch
  11.  
  12. # Check the commit message if we're on an issue branch
  13. if branch.startswith('issue-'):
  14. print "commit-msg: Oh hey, it's an issue branch."
  15. result = re.match('issue-(.*)', branch)
  16. issue_number = result.group(1)
  17. required_message = "ISSUE-%s" % issue_number
  18. with open(commit_msg_filepath, 'r') as f:
  19. content = f.read()
  20. if not content.startswith(required_message):
  21. print "commit-msg: ERROR! The commit message must start with '%s'" % required_message
  22. sys.exit(1)
  23.  
  24. # Check the commit message if we're on an feature branch
  25. if branch.startswith('feature-'):
  26. print "commit-msg: Oh hey, it's an feature branch."
  27. result = re.match('feature-(.*)', branch)
  28. feature_number = result.group(1)
  29. required_message = "FEATURE-%s" % feature_number
  30. with open(commit_msg_filepath, 'r') as f:
  31. content = f.read()
  32. if not content.startswith(required_message):
  33. print "commit-msg: ERROR! The commit message must start with '%s'" % required_message
  34. sys.exit(1)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement