Skip to content

Instantly share code, notes, and snippets.

@evilpie
Created June 8, 2012 10:50
Show Gist options
  • Save evilpie/2894970 to your computer and use it in GitHub Desktop.
Save evilpie/2894970 to your computer and use it in GitHub Desktop.
import hgapi
from bugzilla.agents import BMOAgent
import re
from optparse import OptionParser
# Use this like:
# python hgbzlog.py -c "JavaScript Engine" -r /home/tom/inbound -s 357da346ceb7
parser = OptionParser()
parser.add_option('-c', '--component', help='Limit bugs to certain component.')
parser.add_option('-r', '--repository', help='Path to mercurial repository.')
parser.add_option('-s', '--start', help='Start revision.')
parser.add_option('-e', '--end', default='tip', help='End revision. [default: %default]')
(options, args) = parser.parse_args()
# This should match most of the ways people spell out bug ids
reBug = re.compile('(bug\s+\#?|b=)([0-9]+)', re.I)
# open repository
repo = hgapi.Repo(options.repository)
changesets = {}
log = repo.revisions(slice(options.start, options.end))
for revision in log:
result = reBug.search(revision.desc)
if result:
bug = result.group(2)
if changesets.has_key(bug):
changesets[bug].append(revision)
else:
changesets[bug] = [revision]
# Load our agent for BMO
bmo = BMOAgent()
def chunks(l, n):
""" Yield successive n-sized chunks from l.
"""
for i in xrange(0, len(l), n):
yield l[i:i+n]
ids = changesets.keys()
for c in chunks(ids, 10):
query = {
'bug_id': ','.join(c),
'component': options.component # Let Bugzilla filter out the bugs with the right component
}
bugs = bmo.get_bug_list(query)
for bug in bugs:
print bug
for revision in changesets[str(bug.id)]:
print '\t', revision.rev, revision.desc[:revision.desc.find('\n')]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment