Created
March 8, 2011 22:14
-
-
Save jbalogh/861202 to your computer and use it in GitHub Desktop.
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 | |
""" | |
Usage: | |
git log next..master --oneline | milestones.py | |
git cherry next master -v | milestones.py | |
Requirements: | |
pip install termcolor | |
""" | |
import json | |
import multiprocessing | |
import re | |
import sys | |
import urllib | |
import termcolor | |
API = 'https://api-dev.bugzilla.mozilla.org/latest/bug/%s' | |
bug_re = re.compile('bug (\d+)', re.I) | |
BUGS = {} | |
# Create functions for all the colors and attributes. | |
for attr in termcolor.ATTRIBUTES: | |
globals()[attr] = lambda x, a=attr: termcolor.colored(x, attrs=[a]) | |
for color in termcolor.COLORS: | |
globals()[color] = lambda x, c=color: termcolor.colored(x, c) | |
def milestone(bug): | |
qs = '?include_fields=target_milestone' | |
response = urllib.urlopen(API % bug + qs) | |
return bug, json.loads(response.read()).get('target_milestone') | |
def buggy(msg): | |
return bug_re.sub(lambda x: bold(magenta(x.group(0))), msg) | |
stdin = [line for line in sys.stdin] | |
for line in stdin: | |
rev, msg = line.strip().split(' ', 1) | |
BUGS.update((b, None) for b in bug_re.findall(msg)) | |
BUGS = dict(multiprocessing.Pool(10).map(milestone, BUGS)) | |
for line in stdin: | |
diff, mcolor = '', green | |
if line.startswith('+') or line.startswith('-'): | |
mcolor = green if line.startswith('+') else red | |
diff = mcolor(line[:2]) | |
line = line[2:] | |
rev, msg = line.strip().split(' ', 1) | |
ms = [BUGS[b] for b in bug_re.findall(msg)] | |
ms = '[%s]' % ', '.join(map(mcolor, ms)) if ms else '' | |
print diff, bold(yellow(rev[:8])), buggy(msg), ms |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment