Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python
- import sys, re
- from subprocess import check_output
- commit_msg_filepath = sys.argv[1]
- try:
- branch = check_output(['git', 'symbolic-ref', '--short', 'HEAD'])
- branch = branch.strip().decode("utf-8")
- print('COMMITING INTO BRANCH -> ', branch)
- # Add your Regexp Here
- regex = '(feature|hotfix|bug)\/([A-Za-z]+-[0-9]+)'
- if re.match(regex, branch):
- issue = re.match(regex, branch).group(2)
- print('JIRA ISSUE REFERENCE -> ', issue)
- with open(commit_msg_filepath, 'r+') as fh:
- fh.seek(0, 0)
- commit_msg = fh.read()
- print('COMMIT MSG -> ', commit_msg)
- fh.close()
- with open(commit_msg_filepath, 'w') as fh:
- fh.write('[%s] %s' % (issue, commit_msg))
- elif branch != 'master' and branch != 'dev':
- print('Incorrect branch name')
- print('Using default msg')
- fh.close()
- except Exception as err:
- # we are in a rebase or detached head state
- with open(commit_msg_filepath, 'r') as fh:
- fh.seek(0, 0)
- commit_msg = fh.read()
- print('ERROR FOUND, USING DEFAULT COMMIT MSG -> ', commit_msg)
- fh.close()
- with open(commit_msg_filepath, 'w') as fh:
- fh.write('%s' % (commit_msg))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement