Created
August 14, 2018 18:07
-
-
Save d30jeff/20b80d778fba06784307e53e6baba835 to your computer and use it in GitHub Desktop.
Append branch name to commit message to make life easier
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
import sys, os, re | |
from subprocess import check_output | |
file_path = sys.argv[1] | |
# Get branch name | |
branch_name = check_output(['git', 'symbolic-ref', '--short', '-q', 'HEAD']).strip() | |
# Initialize prefix name | |
prefix = "" | |
# Strip each element that has been separated by '/' and cast to uppercase if it's not empty | |
chunk = [s.strip().upper() for s in branch_name.split('/') if s] | |
if len(chunk) > 1: | |
prefix = '/'.join(chunk[1:]) | |
with open(file_path, 'r+') as f: | |
content = f.read() | |
f.seek(0, 0) | |
if prefix: | |
f.write(': '.join([prefix, content])) | |
else: | |
f.write(content) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Branch name => Commit prefix
story/ticket-12
=>TICKET-12: <commit-message>
story/poop/ticket-13
=>POOP/TICKET-13: <commit-message>
bug/ticket-13
=>TICKET-13: <commit-message>
regular-branch-name
=><commit-message>