OLD | NEW |
---|---|
(Empty) | |
1 #!/usr/bin/env python | |
2 # Copyright (c) 2011 The Chromium Authors. All rights reserved. | |
3 # Use of this source code is governed by a BSD-style license that can be | |
4 # found in the LICENSE file. | |
5 | |
6 """Get rietveld stats. | |
7 | |
8 Example: | |
9 - my_reviews.py -o me@chromium.org -Q for stats for last quarter. | |
10 """ | |
11 import datetime | |
12 import optparse | |
13 import os | |
14 import sys | |
15 | |
16 import rietveld | |
17 | |
18 | |
19 def print_reviews(owner, reviewer, created_after, created_before): | |
20 """Prints issues with the filter. | |
21 | |
22 add with_messages=True to search() call above if you want messages too. | |
23 If you only want numbers, use keys_only=True in the search() call above. | |
24 You can use remote.get_issue_properties(issue, True) to get the data per | |
25 issue. | |
26 """ | |
Dirk Pranke
2011/09/21 20:44:18
This comment mentions with_messages and keys_only,
| |
27 instance_url = 'codereview.chromium.org' | |
28 remote = rietveld.Rietveld(instance_url, None, None) | |
29 for issue in remote.search( | |
30 owner=owner, | |
31 reviewer=reviewer, | |
32 created_after=created_after, | |
33 created_before=created_before, | |
34 ): | |
35 # By default, hide commit-bot and the domain. | |
36 reviewers = set(r.split('@', 1)[0] for r in issue['reviewers']) | |
37 reviewers -= set(('commit-bot',)) | |
38 | |
39 # Available keys are: | |
40 # 'base_url' | |
41 # 'cc' | |
42 # 'closed' | |
43 # 'commit' | |
44 # 'created' | |
45 # 'description' | |
46 # 'issue' | |
47 # 'modified' | |
48 # 'owner' | |
49 # 'owner_email' | |
50 # 'patchsets' | |
51 # 'private' | |
52 # 'reviewers' | |
53 # 'subject' | |
Dirk Pranke
2011/09/21 20:44:18
This list of keys isn't actually used anywhere, is
| |
54 | |
55 # Strip time. | |
56 timestamp = issue['created'][:10] | |
57 print '%d: %s %s' % (issue['issue'], timestamp, ', '.join(reviewers)) | |
58 | |
59 | |
60 def get_previous_quarter(today): | |
61 """There are four quarters, 01-03, 04-06, 07-09, 10-12. | |
62 | |
63 If today is in the last month of a quarter, assume it's the current quarter | |
64 that is requested. | |
65 04 -> 03 | |
66 03 -> 03 | |
67 02 -> 12 (last year) | |
68 01 -> 12 | |
69 12 -> 12 | |
70 etc. | |
71 """ | |
Dirk Pranke
2011/09/21 20:44:18
I'm not sure that lines 65-70 actually make things
| |
72 year = today.year | |
73 month = today.month - (today.month % 3) | |
74 if not month: | |
75 month = 12 | |
76 year -= 1 | |
77 previous_month = month - 2 | |
78 return ( | |
79 '%d-%02d-01' % (year, previous_month), | |
80 '%d-%02d-01' % (year, month)) | |
81 | |
82 | |
83 def main(): | |
84 parser = optparse.OptionParser(description=sys.modules[__name__].__doc__) | |
85 parser.add_option('-o', '--owner') | |
86 parser.add_option('-r', '--reviewer') | |
87 parser.add_option('-c', '--created_after') | |
88 parser.add_option('-C', '--created_before') | |
89 parser.add_option('-Q', '--last_quarter', action='store_true') | |
90 # Remove description formatting | |
91 parser.format_description = lambda x: parser.description | |
92 options, args = parser.parse_args() | |
93 if args: | |
94 parser.error('Args unsupported') | |
95 if not options.owner and not options.reviewer: | |
96 options.owner = os.environ['EMAIL_ADDRESS'] | |
97 if '@' not in options.owner: | |
98 parser.error('Please specify at least -o or -r') | |
99 print 'Defaulting to owner=%s' % options.owner | |
100 if options.last_quarter: | |
101 today = datetime.date.today() | |
102 options.created_after, options.created_before = get_previous_quarter(today) | |
103 print 'Using range %s to %s' % ( | |
104 options.created_after, options.created_before) | |
105 print_reviews( | |
106 options.owner, options.reviewer, | |
107 options.created_after, options.created_before) | |
108 return 0 | |
109 | |
110 | |
111 if __name__ == '__main__': | |
112 sys.exit(main()) | |
OLD | NEW |