Skip to content

Instantly share code, notes, and snippets.

@rhelmer
Created January 12, 2012 00:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save rhelmer/1597699 to your computer and use it in GitHub Desktop.
Save rhelmer/1597699 to your computer and use it in GitHub Desktop.
#!/usr/bin/python
#
# gitzilla
#
# give me a list of git log messages and a target milestone, and I'll show you
# the difference.
#
# Example: git log --oneline v2.3.5..master | ./gitzilla.py -t 2.4
import re
import sys
import optparse
import urllib2
import csv
bug_pattern = re.compile(r'bug\s?\d+', flags=re.IGNORECASE)
bz_baseurl = 'https://bugzilla.mozilla.org/buglist.cgi?query_format=advanced&target_milestone=%s&product=Socorro&ctype=csv'
def main(git_bug_nums, target_milestone):
bz_url = bz_baseurl % target_milestone
bug_reports = csv.DictReader(urllib2.urlopen(bz_url))
bz_bug_nums = set(x['bug_id'] for x in bug_reports)
for num in git_bug_nums:
if num in bz_bug_nums:
print 'OK %s from git is in target milestone %s' % (num, target_milestone)
else:
print 'ERROR %s is not in target milestone %s' % (num, target_milestone)
for num in bz_bug_nums:
if num in git_bug_nums:
print 'OK %s from target milestone %s is in git' % (num, target_milestone)
else:
print 'ERROR %s is in target milestone %s but not in git' % (num, target_milestone)
if __name__ == '__main__':
parser = optparse.OptionParser('usage: %prog [options]')
parser.add_option('-t', '--target_milestone', dest='target_milestone',
type='string', help='target_milestone to check on bz')
(options, args) = parser.parse_args()
target_milestone = options.target_milestone
git_bug_nums = set()
for line in sys.stdin:
commit_msg = line.strip()
bug_msg = bug_pattern.findall(commit_msg)
if bug_msg is None:
print 'ERROR missing bug message in git log: %s' % commit_msg
else:
git_bug_nums = git_bug_nums.union(
set(x.lower().split('bug')[1].strip() for x in bug_msg))
main(git_bug_nums, target_milestone)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment