Skip to content

Instantly share code, notes, and snippets.

@dankilman
Created November 8, 2014 21:22
Show Gist options
  • Save dankilman/ac5f2fde05a8ada5494f to your computer and use it in GitHub Desktop.
Save dankilman/ac5f2fde05a8ada5494f to your computer and use it in GitHub Desktop.
Prefix CFY-XXX to commit messages
#!/bin/python
import re
import subprocess
import sys
CURRENT_BRANCH_CMD = 'git symbolic-ref --short HEAD'
JIRA_ISSUE_REGEX = '(CFY-\d+)-.*?'
output_message_path = sys.argv[1]
branch_name = subprocess.check_output(
CURRENT_BRANCH_CMD.split(' ')).decode('utf-8')
match = re.match(JIRA_ISSUE_REGEX, branch_name)
if match:
jira_issue = match.group(1)
with open(output_message_path) as f:
current_message = f.read()
if not current_message.startswith(jira_issue):
with open(output_message_path, 'w') as f:
f.write('{0} {1}'.format(jira_issue, current_message))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment