Skip to content

Instantly share code, notes, and snippets.

@co3k
Last active August 29, 2015 14:00
Show Gist options
  • Save co3k/11123263 to your computer and use it in GitHub Desktop.
Save co3k/11123263 to your computer and use it in GitHub Desktop.
t-?([0-9]+) なブランチでコミットするとコミットメッセージに Trello-{num} とかカードに対する URL とかを付けてくれるやつ。 git config で trello.baseurl の設定が必要
#!/usr/bin/env python
import re
from subprocess import Popen, PIPE
import sys
COMMIT_EDITMSG = sys.argv[1]
branch = Popen(['git', 'rev-parse', '--abbrev-ref', 'HEAD'], stdout=PIPE).stdout.read().strip()
matched = re.search('t-?([0-9]+)', branch)
if not matched:
sys.exit(0)
base_url = Popen(['git', 'config', '--get', 'trello.baseurl'], stdout=PIPE).stdout.read().strip()
template = open(COMMIT_EDITMSG, 'r').read()
fh = open(COMMIT_EDITMSG, 'w')
fh.write('(Trello-{0})\n\nTrello: {1}/{0}\n{2}'.format(matched.group(1), base_url, template))
@co3k
Copy link
Author

co3k commented Apr 21, 2014

うおー Python 2.6 で subprocess.check_output() 動かないうおー

@co3k
Copy link
Author

co3k commented Apr 22, 2014

t-?([0-9]+) だと短縮 URL に引っかけられない (ボードの ID から導き出せると思ったけど無理っぽい) ので t-([a-zA-Z0-9]+)- で行こうと思うよ

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment