in scripts/year_in_review.py [0:0]
def bugzilla_stats(year):
stats = []
bugzilla = BugzillaAPI(
BZ_URL,
transport=SessionTransport(use_datetime=True),
allow_none=True)
# -------------------------------------------
# Bugs created this year
# -------------------------------------------
bugs = bugzilla.get_bugs(
product=PRODUCTS,
creation_time='%s-01-01' % year,
include_fields=['id', 'creator', 'creation_time'],
history=False,
comments=False)
bugs = bugs['bugs']
total = 0
creators = {}
for bug in bugs:
# We can only get creation_time >= somedate, so we need to nix
# the bugs that are after the year we're looking for.
if bug['creation_time'].year != int(year):
continue
total += 1
creators[bug['creator']] = creators.get(bug['creator'], 0) + 1
creators = sorted(list(creators.items()), key=lambda item: item[1], reverse=True)
stats.append(('Bugs created', {
'total': total,
'breakdown': [
{'name': mem[0].split('@')[0], 'count': mem[1]}
for mem in creators[:10]]
}))
# -------------------------------------------
# Bugs resolved this year
# -------------------------------------------
bugs = bugzilla.get_bugs(
product=PRODUCTS,
last_change_time='%s-01-01' % year,
include_fields=['id', 'summary', 'assigned_to', 'last_change_time', 'resolution'],
status=['RESOLVED', 'VERIFIED', 'CLOSED'],
history=True,
comments=False)
bugs = bugs['bugs']
total = 0
peeps = {}
resolutions = {}
traceback_bugs = []
research_bugs = []
tracker_bugs = []
for bug in bugs:
# We can only get last_change_time >= somedate, so we need to
# nix the bugs that are after the year we're looking for.
if bug['last_change_time'].year != int(year):
continue
if bug['summary'].lower().startswith('[traceback]'):
traceback_bugs.append(bug)
if bug['summary'].lower().startswith('[research]'):
research_bugs.append(bug)
if bug['summary'].lower().startswith('[tracker]'):
tracker_bugs.append(bug)
for hist in bug['history']:
for change in hist['changes']:
if not change['field_name'] == 'resolution':
continue
# I think this history item comes from clearing the
# resolution. i.e. reopening.
if change['added'] == '':
continue
total += 1
# If the bug is marked FIXED, we assume that whoever
# it was assigned to should get the "credit". If it
# wasn't marked FIXED, then it's probably someone
# doing triage and so whoever changed the resolution
# should get "credit".
if (change['added'] == 'FIXED'
and not 'nobody' in bug['assigned_to']):
person = bug['assigned_to']
else:
person = hist['who']
peeps_dict = peeps.setdefault(person, {})
key = change['added']
peeps_dict[key] = peeps_dict.get(key, 0) + 1
resolutions[change['added']] = resolutions.get(
change['added'], 0) + 1
peeps = sorted(list(peeps.items()), key=lambda item: sum(item[1].values()), reverse=True)
stats.append(('Bugs resolved', {
'total': total,
'breakdown': [
{'name': mem[0].split('@')[0],
'total': sum(mem[1].values()),
'breakdown': list(mem[1].items())}
for mem in peeps[:10]
]
}))
# -------------------------------------------
# Resolution stats
# -------------------------------------------
resolutions = sorted(list(resolutions.items()), key=lambda item: item[1])
stats.append(('Bugs resolved breakdown', resolutions))
# -------------------------------------------
# Research bugs
# -------------------------------------------
stats.append(('Research bugs', [
{'id': bug['id'], 'summary': bug['summary']}
for bug in research_bugs
]))
# -------------------------------------------
# Trackers
# -------------------------------------------
stats.append(('Tracker bugs', [
{'id': bug['id'], 'summary': bug['summary']}
for bug in tracker_bugs
]))
return stats