Add the ability to get reviewer stats across all stable branches

This adds a special "all" stable branch value handling for the
reviewers entrypoint. This allows one to do something like:

$ reviewers --stable all --days 90 --output ~/stable-all-reviewers-90

It would be nice to be able to specify a specific project, like nova,
with --stable but that is another change for another day.

Change-Id: I045e982e587c9fb2c53a9cb587f944f09c2c5793
This commit is contained in:
Matt Riedemann 2017-08-30 12:10:52 -04:00
parent 548a85d2a9
commit 73d434b28c
3 changed files with 25 additions and 4 deletions

View File

@ -34,3 +34,14 @@ object containing the following keys:
* core-team: A list of Gerrit usernames to consider as core reviewers across * core-team: A list of Gerrit usernames to consider as core reviewers across
subprojects. subprojects.
* lp_projects: A list of Launchpad project ids to include. * lp_projects: A list of Launchpad project ids to include.
Examples
--------
#. Get reviewer stats for the last 14 days (default) in the stable/pike branch:
``$ reviewers --stable pike --output ~/reviewers-stable-pike-14``
#. Get reviewer stats for the last 90 days across all stable branches:
``$ reviewers --stable all --days 90 --output ~/reviewers-stable-all-90``

View File

@ -136,6 +136,10 @@ def write_pretty(reviewer_data, file_obj, options, reviewers, projects,
else: else:
project_name = projects[0]['name'] project_name = projects[0]['name']
if options.stable: if options.stable:
# Handle the wildcare case.
if options.stable.strip() == 'all':
project_name = 'all open stable branches'
else:
project_name = "stable/%s" % (options.stable) project_name = "stable/%s" % (options.stable)
file_obj.write( file_obj.write(
'Reviews for the last %d days in %s\n' 'Reviews for the last %d days in %s\n'
@ -244,7 +248,8 @@ def main(argv=None):
optparser.add_option( optparser.add_option(
'-s', '--stable', default='', metavar='BRANCH', '-s', '--stable', default='', metavar='BRANCH',
help='Generate stats for the specified stable BRANCH ("havana") ' help='Generate stats for the specified stable BRANCH ("havana") '
'across all integrated projects') 'across all integrated projects. Specify "all" for all '
'open stable branches.')
optparser.add_option( optparser.add_option(
'-o', '--output', default='-', '-o', '--output', default='-',
help='Where to write output. If - stdout is used and only one output ' help='Where to write output. If - stdout is used and only one output '

View File

@ -111,7 +111,8 @@ def get_changes(projects, ssh_user, ssh_key, only_open=False, stable='',
:param bool only_open: If True, get only the not closed reviews. :param bool only_open: If True, get only the not closed reviews.
:param str stable: :param str stable:
Name of the stable branch. If empty string, the changesets are not Name of the stable branch. If empty string, the changesets are not
filtered by any branch. filtered by any branch. The special value "all" is handled to get
changes for all open stable branches.
:return: List of de-serialized JSON changeset data as returned by gerrit. :return: List of de-serialized JSON changeset data as returned by gerrit.
:rtype: list :rtype: list
@ -189,6 +190,10 @@ def get_changes(projects, ssh_user, ssh_key, only_open=False, stable='',
if only_open: if only_open:
cmd += ' status:open' cmd += ' status:open'
if stable: if stable:
# Check for "all" to query all stable branches.
if stable.strip() == 'all':
cmd += ' branch:^stable/.*'
else:
cmd += ' branch:stable/%s' % stable cmd += ' branch:stable/%s' % stable
if new_count: if new_count:
cmd += ' --start %d' % new_count cmd += ' --start %d' % new_count