def print_bugzilla_stats()

in scripts/in_review.py [0:0]


def print_bugzilla_stats(from_date, to_date):
    # ------------------------------------------------
    # Bug creation stats
    # ------------------------------------------------
    params = {
        'product': BUGZILLA_PRODUCT,
        'f1': 'creation_ts',
        'o1': 'greaterthaneq',
        'v1': from_date.strftime('%Y-%m-%d'),
        'f2': 'creation_ts',
        'o2': 'lessthan',
        'v2': to_date.strftime('%Y-%m-%d')
    }

    json_data = fetch_bugs(params)

    creation_count = len(json_data['bugs'])

    creators = {}
    for bug in json_data['bugs']:
        creator = bug['creator_detail']['real_name']
        if not creator:
            creator = bug['creator'].split('@')[0]
        creators[creator] = creators.get(creator, 0) + 1
        all_people.add(creator)

    print('Bugs created: %s' % creation_count)
    print('Creators: %s' % len(creators))
    print('')
    creators = sorted(list(creators.items()), reverse=True, key=lambda item: item[1])
    for person, count in creators:
        print(' %34s : %s' % (person[:30].encode('utf-8'), count))
    print('')

    # ------------------------------------------------
    # Bug resolution stats
    # ------------------------------------------------
    params = {
        'product': BUGZILLA_PRODUCT,
        'f1': 'cf_last_resolved',
        'o1': 'greaterthaneq',
        'v1': from_date.strftime('%Y-%m-%d'),
        'f2': 'cf_last_resolved',
        'o2': 'lessthan',
        'v2': to_date.strftime('%Y-%m-%d')
    }

    json_data = fetch_bugs(params)

    resolved_count = len(json_data['bugs'])
    resolved_map = {}
    resolvers = {}
    traceback_bugs = []
    research_bugs = []
    tracker_bugs = []
    commenters = {}

    for bug in json_data['bugs']:
        summary = bug['summary'].lower()
        if summary.startswith('[traceback]'):
            traceback_bugs.append(bug)
        elif summary.startswith('[research]'):
            research_bugs.append(bug)
        elif summary.startswith('[tracker]'):
            tracker_bugs.append(bug)

        history = fetch_bug_history(bug['id'])

        resolution = bug['resolution']
        resolved_map[resolution] = resolved_map.get(resolution, 0) + 1
        assigned = bug['assigned_to_detail']['real_name']
        if not assigned:
            assigned = bug['assigned_to'].split('@')[0]

        if 'nobody' in assigned.lower():
            # If no one was assigned, we give "credit" to whoever
            # triaged the bug. We go through the history in reverse
            # order because the "resolver" is the last person to
            # resolve the bug.
            for item in reversed(history['bugs'][0]['history']):
                # See if this item in the history is the resolving event.
                # If it is, then we know who resolved the bug and we
                # can stop looking at history.
                changes = [change for change in item['changes']
                           if change['field_name'] == 'status' and
                           change['added'] == 'RESOLVED']

                if not changes:
                    continue

                assigned = item['who']
                break

        if assigned:
            if '@' in assigned:
                assigned = assigned.split('@')[0]

            resolvers[assigned] = resolvers.get(assigned, 0) + 1
            all_people.add(assigned)

        # Now get all the commenters
        comments = fetch_bug_comments(bug['id'])
        # The Bugzilla REST api has some interesting things about it.
        for comment in comments['bugs'][str(bug['id'])]['comments']:
            commenter = comment['author']
            if '@' in commenter:
                commenter = commenter.split('@')[0]

            commenters[commenter] = commenters.get(commenter, 0) + 1
            all_people.add(commenter)

    print('Bugs resolved: %s' % resolved_count)
    print('')
    for resolution, count in list(resolved_map.items()):
        print(' %34s : %s' % (resolution, count))

    print('')
    for title, count in [('Tracebacks', len(traceback_bugs)),
                         ('Research', len(research_bugs)),
                         ('Tracker', len(tracker_bugs))]:
        print(' %34s : %s' % (title, count))

    print('')
    print('Research bugs: %s' % len(research_bugs))
    print('')
    for bug in research_bugs:
        print(wrap('%s: %s' % (bug['id'], bug['summary']),
                   subsequent='        '))

    print('')
    print('Tracker bugs: %s' % len(tracker_bugs))
    print('')
    for bug in tracker_bugs:
        print(wrap('%s: %s' % (bug['id'], bug['summary']),
                   subsequent='        '))

    print('')
    print('Resolvers: %s' % len(resolvers))
    print('')
    resolvers = sorted(list(resolvers.items()), reverse=True,
                       key=lambda item: item[1])
    for person, count in resolvers:
        print(' %34s : %s' % (person[:30].encode('utf-8'), count))

    print('')
    print('Commenters: %s' % len(commenters))
    print('')
    commenters = sorted(list(commenters.items()), reverse=True,
                        key=lambda item: item[1])
    for person, count in commenters:
        print(' %34s : %s' % (person[:30].encode('utf-8'), count))