Skip to content

Instantly share code, notes, and snippets.

@lonnen
Forked from rhelmer/gist:1597699
Created January 12, 2012 01:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lonnen/1597805 to your computer and use it in GitHub Desktop.
Save lonnen/1597805 to your computer and use it in GitHub Desktop.
the difference between git and our bugzilla milestone
#!/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 & bz_bug_nums):
print 'OK %s in git is in target milestone %s' % (num, target_milestone)
for num in (bz_bug_nums - git_bug_nums):
print 'WARNING %s is in target milestone %s but not in git' % (num, target_milestone)
for num in (git_bug_nums - bz_bug_nums):
print 'ERROR %s is in git but not in target milestone %s' % (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