Commit 0bccb920 authored by maruel@chromium.org's avatar maruel@chromium.org

Actually, it's filtering by reviews that is useful, clean up the code accordingly

It's now live on codereview.appspot, codereview.chromium and the internal
instance so it's far more easier to get review stats now.

R=dpranke@chromium.org
BUG=
TEST=


Review URL: http://codereview.chromium.org/7989013

git-svn-id: svn://svn.chromium.org/chrome/trunk/tools/depot_tools@102331 0039d316-1c4b-4281-b951-d872f2087c98
parent 70e91c0d
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
# Use of this source code is governed by a BSD-style license that can be # Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file. # found in the LICENSE file.
"""Get rietveld stats. """Get rietveld stats about the review you done, or forgot to do.
Example: Example:
- my_reviews.py -o me@chromium.org -Q for stats for last quarter. - my_reviews.py -o me@chromium.org -Q for stats for last quarter.
...@@ -16,43 +16,58 @@ import sys ...@@ -16,43 +16,58 @@ import sys
import rietveld import rietveld
def print_reviews(owner, reviewer, created_after, created_before, instance_url): def username(email):
"""Prints issues with the filter. return email.split('@', 1)[0]
Set with_messages=True to search() call bellow if you want each message too.
If you only want issue numbers, use keys_only=True in the search() call. def print_reviews(reviewer, created_after, created_before, instance_url):
You can then use remote.get_issue_properties(issue, True) to get the data per """Prints issues the dude reviewed."""
issue.
"""
remote = rietveld.Rietveld(instance_url, None, None) remote = rietveld.Rietveld(instance_url, None, None)
total = 0
actually_reviewed = 0
# See def search() in rietveld.py to see all the filters you can use. # See def search() in rietveld.py to see all the filters you can use.
for issue in remote.search( for issue in remote.search(
owner=owner,
reviewer=reviewer, reviewer=reviewer,
created_after=created_after, created_after=created_after,
created_before=created_before, created_before=created_before,
keys_only=False, with_messages=True,
with_messages=False,
): ):
total += 1
# By default, hide commit-bot and the domain. # By default, hide commit-bot and the domain.
reviewers = set(r.split('@', 1)[0] for r in issue['reviewers']) reviewers = set(username(r) for r in issue['reviewers'])
reviewers -= set(('commit-bot',)) reviewers -= set(['commit-bot'])
# Strip time. # Strip time.
timestamp = issue['created'][:10] timestamp = issue['created'][:10]
if any(
username(msg['sender']) == username(reviewer)
for msg in issue['messages']):
reviewed = ' x '
actually_reviewed += 1
else:
reviewed = ' '
# More information is available, print issue.keys() to see them. # More information is available, print issue.keys() to see them.
print '%d: %s %s' % (issue['issue'], timestamp, ', '.join(reviewers)) print '%7d %s %s O:%-15s R:%s' % (
issue['issue'],
timestamp,
def print_count(owner, reviewer, created_after, created_before, instance_url): reviewed,
username(issue['owner_email']),
', '.join(reviewers))
percent = 0.
if total:
percent = (actually_reviewed * 100. / total)
print 'You actually reviewed %d issues out of %d (%1.1f%%)' % (
actually_reviewed, total, percent)
def print_count(reviewer, created_after, created_before, instance_url):
remote = rietveld.Rietveld(instance_url, None, None) remote = rietveld.Rietveld(instance_url, None, None)
print len(list(remote.search( print len(list(remote.search(
owner=owner,
reviewer=reviewer, reviewer=reviewer,
created_after=created_after, created_after=created_after,
created_before=created_before, created_before=created_before,
keys_only=False))) keys_only=True)))
def get_previous_quarter(today): def get_previous_quarter(today):
...@@ -89,9 +104,9 @@ def main(): ...@@ -89,9 +104,9 @@ def main():
'--count', action='store_true', '--count', action='store_true',
help='Just count instead of printing individual issues') help='Just count instead of printing individual issues')
parser.add_option( parser.add_option(
'-o', '--owner', metavar='<email>', help='Filter on issue owner') '-r', '--reviewer', metavar='<email>',
parser.add_option( default=os.environ.get('EMAIL_ADDRESS'),
'-r', '--reviewer', metavar='<email>', help='Filter on issue reviewer') help='Filter on issue reviewer, default=%default')
parser.add_option( parser.add_option(
'-c', '--created_after', metavar='<date>', '-c', '--created_after', metavar='<date>',
help='Filter issues created after the date') help='Filter issues created after the date')
...@@ -111,11 +126,8 @@ def main(): ...@@ -111,11 +126,8 @@ def main():
options, args = parser.parse_args() options, args = parser.parse_args()
if args: if args:
parser.error('Args unsupported') parser.error('Args unsupported')
if not options.owner and not options.reviewer:
options.owner = os.environ['EMAIL_ADDRESS'] print >> sys.stderr, 'Searching for reviews by %s' % options.reviewer
if '@' not in options.owner:
parser.error('Please specify at least -o or -r')
print >> sys.stderr, 'Defaulting to owner=%s' % options.owner
if options.last_quarter: if options.last_quarter:
options.created_after = created_after options.created_after = created_after
options.created_before = created_before options.created_before = created_before
...@@ -123,13 +135,15 @@ def main(): ...@@ -123,13 +135,15 @@ def main():
options.created_after, options.created_before) options.created_after, options.created_before)
if options.count: if options.count:
print_count( print_count(
options.owner, options.reviewer, options.reviewer,
options.created_after, options.created_before, options.created_after,
options.created_before,
options.instance_url) options.instance_url)
else: else:
print_reviews( print_reviews(
options.owner, options.reviewer, options.reviewer,
options.created_after, options.created_before, options.created_after,
options.created_before,
options.instance_url) options.instance_url)
return 0 return 0
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment