Skip to content

Instantly share code, notes, and snippets.

@Runman44
Created October 24, 2018 11:23
Show Gist options
  • Save Runman44/f1f6530e150bc55be6a0b5ef61cab5b7 to your computer and use it in GitHub Desktop.
Save Runman44/f1f6530e150bc55be6a0b5ef61cab5b7 to your computer and use it in GitHub Desktop.
git_hook_prefix_commit_msg
#!/usr/bin/env python
import sys, re
from subprocess import check_output
commit_msg_filepath = sys.argv[1]
branch = check_output(['git', 'symbolic-ref', '--short', 'HEAD']).strip()
regex = '(STRY.\d+)'
if re.search(regex, branch):
issue = re.search(regex, branch).group()
with open(commit_msg_filepath, 'r+') as fh:
commit_msg = fh.read()
fh.seek(0, 0)
fh.write('[%s] %s' % (issue, commit_msg))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment