From 73d434b28ce56c7bfd280750dec1f7e55e9d61b8 Mon Sep 17 00:00:00 2001 From: Matt Riedemann Date: Wed, 30 Aug 2017 12:10:52 -0400 Subject: [PATCH] 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 --- README.rst | 11 +++++++++++ reviewstats/cmd/reviewers.py | 9 +++++++-- reviewstats/utils.py | 9 +++++++-- 3 files changed, 25 insertions(+), 4 deletions(-) diff --git a/README.rst b/README.rst index 0e34477..d337ded 100644 --- a/README.rst +++ b/README.rst @@ -34,3 +34,14 @@ object containing the following keys: * core-team: A list of Gerrit usernames to consider as core reviewers across subprojects. * 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`` diff --git a/reviewstats/cmd/reviewers.py b/reviewstats/cmd/reviewers.py index 3db21f1..35e7c81 100755 --- a/reviewstats/cmd/reviewers.py +++ b/reviewstats/cmd/reviewers.py @@ -136,7 +136,11 @@ def write_pretty(reviewer_data, file_obj, options, reviewers, projects, else: project_name = projects[0]['name'] if options.stable: - project_name = "stable/%s" % (options.stable) + # Handle the wildcare case. + if options.stable.strip() == 'all': + project_name = 'all open stable branches' + else: + project_name = "stable/%s" % (options.stable) file_obj.write( 'Reviews for the last %d days in %s\n' % (options.days, project_name)) @@ -244,7 +248,8 @@ def main(argv=None): optparser.add_option( '-s', '--stable', default='', metavar='BRANCH', 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( '-o', '--output', default='-', help='Where to write output. If - stdout is used and only one output ' diff --git a/reviewstats/utils.py b/reviewstats/utils.py index d0ce068..81d591b 100644 --- a/reviewstats/utils.py +++ b/reviewstats/utils.py @@ -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 str stable: 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. :rtype: list @@ -189,7 +190,11 @@ def get_changes(projects, ssh_user, ssh_key, only_open=False, stable='', if only_open: cmd += ' status:open' if stable: - cmd += ' branch:stable/%s' % stable + # Check for "all" to query all stable branches. + if stable.strip() == 'all': + cmd += ' branch:^stable/.*' + else: + cmd += ' branch:stable/%s' % stable if new_count: cmd += ' --start %d' % new_count else: