Advertisement
Guest User

Untitled

a guest
Jul 19th, 2019
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.14 KB | None | 0 0
  1. #!/usr/bin/env python
  2. import sys, re
  3. from subprocess import check_output
  4.  
  5. commit_msg_filepath = sys.argv[1]
  6. try:
  7. branch = check_output(['git', 'symbolic-ref', '--short', 'HEAD'])
  8. branch = branch.strip().decode("utf-8")
  9. print('COMMITING INTO BRANCH -> ', branch)
  10. # Add your Regexp Here
  11. regex = '(feature|hotfix|bug)\/([A-Za-z]+-[0-9]+)'
  12. if re.match(regex, branch):
  13. issue = re.match(regex, branch).group(2)
  14. print('JIRA ISSUE REFERENCE -> ', issue)
  15. with open(commit_msg_filepath, 'r+') as fh:
  16. fh.seek(0, 0)
  17. commit_msg = fh.read()
  18. print('COMMIT MSG -> ', commit_msg)
  19. fh.close()
  20. with open(commit_msg_filepath, 'w') as fh:
  21. fh.write('[%s] %s' % (issue, commit_msg))
  22. elif branch != 'master' and branch != 'dev':
  23. print('Incorrect branch name')
  24. print('Using default msg')
  25. fh.close()
  26. except Exception as err:
  27. # we are in a rebase or detached head state
  28. with open(commit_msg_filepath, 'r') as fh:
  29. fh.seek(0, 0)
  30. commit_msg = fh.read()
  31. print('ERROR FOUND, USING DEFAULT COMMIT MSG -> ', commit_msg)
  32. fh.close()
  33. with open(commit_msg_filepath, 'w') as fh:
  34. fh.write('%s' % (commit_msg))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement