| 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 1768 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1779 print 'Issue number: %s (%s)' % (cl.GetIssue(), cl.GetIssueURL()) | 1779 print 'Issue number: %s (%s)' % (cl.GetIssue(), cl.GetIssueURL()) |
| 1780 return 0 | 1780 return 0 |
| 1781 | 1781 |
| 1782 | 1782 |
| 1783 def CMDcomments(parser, args): | 1783 def CMDcomments(parser, args): |
| 1784 """Shows or posts review comments for any changelist.""" | 1784 """Shows or posts review comments for any changelist.""" |
| 1785 parser.add_option('-a', '--add-comment', dest='comment', | 1785 parser.add_option('-a', '--add-comment', dest='comment', |
| 1786 help='comment to add to an issue') | 1786 help='comment to add to an issue') |
| 1787 parser.add_option('-i', dest='issue', | 1787 parser.add_option('-i', dest='issue', |
| 1788 help="review issue id (defaults to current issue)") | 1788 help="review issue id (defaults to current issue)") |
| 1789 parser.add_option('-j', '--json-file', |
| 1790 help='File to write JSON summary to') |
| 1789 auth.add_auth_options(parser) | 1791 auth.add_auth_options(parser) |
| 1790 options, args = parser.parse_args(args) | 1792 options, args = parser.parse_args(args) |
| 1791 auth_config = auth.extract_auth_config_from_options(options) | 1793 auth_config = auth.extract_auth_config_from_options(options) |
| 1792 | 1794 |
| 1793 issue = None | 1795 issue = None |
| 1794 if options.issue: | 1796 if options.issue: |
| 1795 try: | 1797 try: |
| 1796 issue = int(options.issue) | 1798 issue = int(options.issue) |
| 1797 except ValueError: | 1799 except ValueError: |
| 1798 DieWithError('A review issue id is expected to be a number') | 1800 DieWithError('A review issue id is expected to be a number') |
| 1799 | 1801 |
| 1800 cl = Changelist(issue=issue, auth_config=auth_config) | 1802 cl = Changelist(issue=issue, auth_config=auth_config) |
| 1801 | 1803 |
| 1802 if options.comment: | 1804 if options.comment: |
| 1803 cl.AddComment(options.comment) | 1805 cl.AddComment(options.comment) |
| 1804 return 0 | 1806 return 0 |
| 1805 | 1807 |
| 1806 data = cl.GetIssueProperties() | 1808 data = cl.GetIssueProperties() |
| 1809 summary = [] |
| 1807 for message in sorted(data.get('messages', []), key=lambda x: x['date']): | 1810 for message in sorted(data.get('messages', []), key=lambda x: x['date']): |
| 1811 summary.append({ |
| 1812 'date': message['date'], |
| 1813 'lgtm': False, |
| 1814 'message': message['text'], |
| 1815 'not_lgtm': False, |
| 1816 'sender': message['sender'], |
| 1817 }) |
| 1808 if message['disapproval']: | 1818 if message['disapproval']: |
| 1809 color = Fore.RED | 1819 color = Fore.RED |
| 1820 summary[-1]['not lgtm'] = True |
| 1810 elif message['approval']: | 1821 elif message['approval']: |
| 1811 color = Fore.GREEN | 1822 color = Fore.GREEN |
| 1823 summary[-1]['lgtm'] = True |
| 1812 elif message['sender'] == data['owner_email']: | 1824 elif message['sender'] == data['owner_email']: |
| 1813 color = Fore.MAGENTA | 1825 color = Fore.MAGENTA |
| 1814 else: | 1826 else: |
| 1815 color = Fore.BLUE | 1827 color = Fore.BLUE |
| 1816 print '\n%s%s %s%s' % ( | 1828 print '\n%s%s %s%s' % ( |
| 1817 color, message['date'].split('.', 1)[0], message['sender'], | 1829 color, message['date'].split('.', 1)[0], message['sender'], |
| 1818 Fore.RESET) | 1830 Fore.RESET) |
| 1819 if message['text'].strip(): | 1831 if message['text'].strip(): |
| 1820 print '\n'.join(' ' + l for l in message['text'].splitlines()) | 1832 print '\n'.join(' ' + l for l in message['text'].splitlines()) |
| 1833 if options.json_file: |
| 1834 with open(options.json_file, 'wb') as f: |
| 1835 json.dump(summary, f) |
| 1821 return 0 | 1836 return 0 |
| 1822 | 1837 |
| 1823 | 1838 |
| 1824 def CMDdescription(parser, args): | 1839 def CMDdescription(parser, args): |
| 1825 """Brings up the editor for the current CL's description.""" | 1840 """Brings up the editor for the current CL's description.""" |
| 1826 parser.add_option('-d', '--display', action='store_true', | 1841 parser.add_option('-d', '--display', action='store_true', |
| 1827 help='Display the description instead of opening an editor') | 1842 help='Display the description instead of opening an editor') |
| 1828 auth.add_auth_options(parser) | 1843 auth.add_auth_options(parser) |
| 1829 options, _ = parser.parse_args(args) | 1844 options, _ = parser.parse_args(args) |
| 1830 auth_config = auth.extract_auth_config_from_options(options) | 1845 auth_config = auth.extract_auth_config_from_options(options) |
| (...skipping 1750 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3581 if __name__ == '__main__': | 3596 if __name__ == '__main__': |
| 3582 # These affect sys.stdout so do it outside of main() to simplify mocks in | 3597 # These affect sys.stdout so do it outside of main() to simplify mocks in |
| 3583 # unit testing. | 3598 # unit testing. |
| 3584 fix_encoding.fix_encoding() | 3599 fix_encoding.fix_encoding() |
| 3585 colorama.init() | 3600 colorama.init() |
| 3586 try: | 3601 try: |
| 3587 sys.exit(main(sys.argv[1:])) | 3602 sys.exit(main(sys.argv[1:])) |
| 3588 except KeyboardInterrupt: | 3603 except KeyboardInterrupt: |
| 3589 sys.stderr.write('interrupted\n') | 3604 sys.stderr.write('interrupted\n') |
| 3590 sys.exit(1) | 3605 sys.exit(1) |
| OLD | NEW |