OLD | NEW |
---|---|
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | 2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. |
3 # Use of this source code is governed by a BSD-style license that can be | 3 # Use of this source code is governed by a BSD-style license that can be |
4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
5 | 5 |
6 # Copyright (C) 2008 Evan Martin <martine@danga.com> | 6 # Copyright (C) 2008 Evan Martin <martine@danga.com> |
7 | 7 |
8 """A git-command for integrating reviews on Rietveld.""" | 8 """A git-command for integrating reviews on Rietveld.""" |
9 | 9 |
10 from distutils.version import LooseVersion | 10 from distutils.version import LooseVersion |
(...skipping 1758 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1769 print 'Issue number: %s (%s)' % (cl.GetIssue(), cl.GetIssueURL()) | 1769 print 'Issue number: %s (%s)' % (cl.GetIssue(), cl.GetIssueURL()) |
1770 return 0 | 1770 return 0 |
1771 | 1771 |
1772 | 1772 |
1773 def CMDcomments(parser, args): | 1773 def CMDcomments(parser, args): |
1774 """Shows or posts review comments for any changelist.""" | 1774 """Shows or posts review comments for any changelist.""" |
1775 parser.add_option('-a', '--add-comment', dest='comment', | 1775 parser.add_option('-a', '--add-comment', dest='comment', |
1776 help='comment to add to an issue') | 1776 help='comment to add to an issue') |
1777 parser.add_option('-i', dest='issue', | 1777 parser.add_option('-i', dest='issue', |
1778 help="review issue id (defaults to current issue)") | 1778 help="review issue id (defaults to current issue)") |
1779 parser.add_option('-j', '--json-file', | |
1780 help='File to write JSON summary to') | |
1779 auth.add_auth_options(parser) | 1781 auth.add_auth_options(parser) |
1780 options, args = parser.parse_args(args) | 1782 options, args = parser.parse_args(args) |
1781 auth_config = auth.extract_auth_config_from_options(options) | 1783 auth_config = auth.extract_auth_config_from_options(options) |
1782 | 1784 |
1783 issue = None | 1785 issue = None |
1784 if options.issue: | 1786 if options.issue: |
1785 try: | 1787 try: |
1786 issue = int(options.issue) | 1788 issue = int(options.issue) |
1787 except ValueError: | 1789 except ValueError: |
1788 DieWithError('A review issue id is expected to be a number') | 1790 DieWithError('A review issue id is expected to be a number') |
1789 | 1791 |
1790 cl = Changelist(issue=issue, auth_config=auth_config) | 1792 cl = Changelist(issue=issue, auth_config=auth_config) |
1791 | 1793 |
1792 if options.comment: | 1794 if options.comment: |
1793 cl.AddComment(options.comment) | 1795 cl.AddComment(options.comment) |
1794 return 0 | 1796 return 0 |
1795 | 1797 |
1796 data = cl.GetIssueProperties() | 1798 data = cl.GetIssueProperties() |
1799 summary = [] | |
1797 for message in sorted(data.get('messages', []), key=lambda x: x['date']): | 1800 for message in sorted(data.get('messages', []), key=lambda x: x['date']): |
1801 summary.append({ | |
1802 'date': message['date'], | |
1803 'lgtm': False, | |
1804 'message': message['text'], | |
1805 'not lgtm': False, | |
Vadim Sh.
2015/09/15 03:15:34
nit: not_lgtm
smut
2015/09/15 16:18:41
Done.
| |
1806 'sender': message['sender'], | |
1807 }) | |
1798 if message['disapproval']: | 1808 if message['disapproval']: |
1799 color = Fore.RED | 1809 color = Fore.RED |
1810 summary[-1]['not lgtm'] = True | |
1800 elif message['approval']: | 1811 elif message['approval']: |
1801 color = Fore.GREEN | 1812 color = Fore.GREEN |
1813 summary[-1]['lgtm'] = True | |
1802 elif message['sender'] == data['owner_email']: | 1814 elif message['sender'] == data['owner_email']: |
1803 color = Fore.MAGENTA | 1815 color = Fore.MAGENTA |
1804 else: | 1816 else: |
1805 color = Fore.BLUE | 1817 color = Fore.BLUE |
1806 print '\n%s%s %s%s' % ( | 1818 print '\n%s%s %s%s' % ( |
1807 color, message['date'].split('.', 1)[0], message['sender'], | 1819 color, message['date'].split('.', 1)[0], message['sender'], |
1808 Fore.RESET) | 1820 Fore.RESET) |
1809 if message['text'].strip(): | 1821 if message['text'].strip(): |
1810 print '\n'.join(' ' + l for l in message['text'].splitlines()) | 1822 print '\n'.join(' ' + l for l in message['text'].splitlines()) |
1823 if options.json_file: | |
1824 with open(options.json_file, 'wb') as f: | |
1825 json.dump(summary, f) | |
1811 return 0 | 1826 return 0 |
1812 | 1827 |
1813 | 1828 |
1814 def CMDdescription(parser, args): | 1829 def CMDdescription(parser, args): |
1815 """Brings up the editor for the current CL's description.""" | 1830 """Brings up the editor for the current CL's description.""" |
1816 parser.add_option('-d', '--display', action='store_true', | 1831 parser.add_option('-d', '--display', action='store_true', |
1817 help='Display the description instead of opening an editor') | 1832 help='Display the description instead of opening an editor') |
1818 auth.add_auth_options(parser) | 1833 auth.add_auth_options(parser) |
1819 options, _ = parser.parse_args(args) | 1834 options, _ = parser.parse_args(args) |
1820 auth_config = auth.extract_auth_config_from_options(options) | 1835 auth_config = auth.extract_auth_config_from_options(options) |
(...skipping 1737 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3558 if __name__ == '__main__': | 3573 if __name__ == '__main__': |
3559 # These affect sys.stdout so do it outside of main() to simplify mocks in | 3574 # These affect sys.stdout so do it outside of main() to simplify mocks in |
3560 # unit testing. | 3575 # unit testing. |
3561 fix_encoding.fix_encoding() | 3576 fix_encoding.fix_encoding() |
3562 colorama.init() | 3577 colorama.init() |
3563 try: | 3578 try: |
3564 sys.exit(main(sys.argv[1:])) | 3579 sys.exit(main(sys.argv[1:])) |
3565 except KeyboardInterrupt: | 3580 except KeyboardInterrupt: |
3566 sys.stderr.write('interrupted\n') | 3581 sys.stderr.write('interrupted\n') |
3567 sys.exit(1) | 3582 sys.exit(1) |
OLD | NEW |