Skip to content

Instantly share code, notes, and snippets.

@DeepSpawn
Created November 22, 2015 07:20
Show Gist options
  • Save DeepSpawn/7334e5dd6588ca58d7b5 to your computer and use it in GitHub Desktop.
Save DeepSpawn/7334e5dd6588ca58d7b5 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
import sys, re
from subprocess import check_output
commit_msg_filepath = sys.argv[1]
issue_key_regex = "([A-Z][A-Z]+-\d+)"
branch = check_output(['git', 'symbolic-ref', '--short', 'HEAD']).strip()
issue_key_match = re.match(issue_key_regex, branch)
if issue_key_match:
issue_key = issue_key_match.group(0)
with open(commit_msg_filepath, 'r+') as f:
content = f.read()
f.seek(0)
f.write("%s: \n%s" % (issue_key,content))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment