Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(342)

Side by Side Diff: tools/add_codereview_message.py

Issue 330423004: Use new common tools in Python scripts (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: append Created 6 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « PRESUBMIT.py ('k') | tools/fix_pythonpath.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 #!/usr/bin/python2 1 #!/usr/bin/python2
2 2
3 # Copyright 2014 Google Inc. 3 # Copyright 2014 Google Inc.
4 # 4 #
5 # Use of this source code is governed by a BSD-style license that can be 5 # Use of this source code is governed by a BSD-style license that can be
6 # found in the LICENSE file. 6 # found in the LICENSE file.
7 7
8 """Add message to codereview issue. 8 """Add message to codereview issue.
9 9
10 This script takes a codereview URL or a codereview issue number as its 10 This script takes a codereview issue number as its argument and a (possibly
11 argument and a (possibly multi-line) message on stdin. It then calls 11 multi-line) message on stdin. It appends the message to the given issue.
12 `git cl upload` to append the message to the given codereview issue.
13 12
14 Usage: 13 Usage:
15 echo MESSAGE | %prog -c CHECKOUT_PATH CODEREVIEW_ISSUE 14 echo MESSAGE | %prog CODEREVIEW_ISSUE
16 or: 15 or:
17 cd /path/to/git/checkout
18 %prog CODEREVIEW_ISSUE <<EOF 16 %prog CODEREVIEW_ISSUE <<EOF
19 MESSAGE 17 MESSAGE
20 EOF 18 EOF
21 or: 19 or:
22 %prog --help 20 %prog --help
23 """ 21 """
24 22
25 import optparse 23 import optparse
26 import os
27 import sys 24 import sys
28 25
29 import git_utils 26 import fix_pythonpath # pylint: disable=W0611
30 import misc_utils 27 from common.py.utils import find_depot_tools # pylint: disable=W0611
28 import rietveld
31 29
32 30
33 DEFAULT_REVIEWERS = ','.join([ 31 RIETVELD_URL = 'https://codereview.chromium.org'
34 'rmistry@google.com',
35 'reed@google.com',
36 'bsalomon@google.com',
37 'robertphillips@google.com',
38 ])
39 32
40 33
41 DEFAULT_CC_LIST = ','.join([ 34 def add_codereview_message(issue, message):
42 'skia-team@google.com',
43 ])
44
45
46 def add_codereview_message(codereview_url, message, checkout_path,
47 skip_cl_upload, verbose, reviewers, cclist):
48 """Add a message to a given codereview. 35 """Add a message to a given codereview.
49 36
50 Args: 37 Args:
51 codereview_url: (string) we will extract the issue number from 38 codereview_url: (string) we will extract the issue number from
52 this url, or this could simply be the issue number. 39 this url, or this could simply be the issue number.
53 message: (string) will be passed to `git cl upload -m $MESSAGE` 40 message: (string) message to add.
54 checkout_path: (string) location of the git
55 repository checkout to be used.
56 skip_cl_upload: (boolean) if true, don't actually
57 add the message and keep the temporary branch around.
58 verbose: (boolean) print out details useful for debugging.
59 reviewers: (string) comma-separated list of reviewers
60 cclist: (string) comma-separated list of addresses to be
61 carbon-copied
62 """ 41 """
63 # pylint: disable=I0011,R0913 42 # Passing None for the email and password will result in a prompt or
64 git = git_utils.git_executable() 43 # reuse of existing cached credentials.
65 issue = codereview_url.strip('/').split('/')[-1] 44 my_rietveld = rietveld.Rietveld(RIETVELD_URL, email=None, password=None)
66 vsp = misc_utils.VerboseSubprocess(verbose) 45
67 if skip_cl_upload: 46 my_rietveld.add_comment(issue, message)
68 branch_name = 'issue_%s' % issue
69 else:
70 branch_name = None
71 upstream = 'origin/master'
72
73 with misc_utils.ChangeDir(checkout_path, verbose):
74 vsp.check_call([git, 'fetch', '-q', 'origin'])
75
76 with git_utils.ChangeGitBranch(branch_name, upstream, verbose):
77 vsp.check_call([git, 'cl', 'patch', issue])
78
79 git_upload = [
80 git, 'cl', 'upload', '-t', 'bot report', '-m', message]
81 if cclist:
82 git_upload.append('--cc=' + cclist)
83 if reviewers:
84 git_upload.append('--reviewers=' + reviewers)
85
86 if skip_cl_upload:
87 branch_name = git_utils.git_branch_name(verbose)
88 space = ' '
89 print 'You should call:'
90 misc_utils.print_subprocess_args(space, ['cd', os.getcwd()])
91 misc_utils.print_subprocess_args(
92 space, [git, 'checkout', branch_name])
93 misc_utils.print_subprocess_args(space, git_upload)
94 else:
95 vsp.check_call(git_upload)
96 print vsp.check_output([git, 'cl', 'issue'])
97 47
98 48
99 def main(argv): 49 def main(argv):
100 """main function; see module-level docstring and GetOptionParser help. 50 """main function; see module-level docstring and GetOptionParser help.
101 51
102 Args: 52 Args:
103 argv: sys.argv[1:]-type argument list. 53 argv: sys.argv[1:]-type argument list.
104 """ 54 """
105 option_parser = optparse.OptionParser(usage=__doc__) 55 option_parser = optparse.OptionParser(usage=__doc__)
106 option_parser.add_option( 56 _, arguments = option_parser.parse_args(argv)
107 '-c', '--checkout_path',
108 default=os.curdir,
109 help='Path to the Git repository checkout,'
110 ' defaults to current working directory.')
111 option_parser.add_option(
112 '', '--skip_cl_upload', action='store_true', default=False,
113 help='Skip the cl upload step; useful for testing.')
114 option_parser.add_option(
115 '', '--verbose', action='store_true', dest='verbose', default=False,
116 help='Do not suppress the output from `git cl`.',)
117 option_parser.add_option(
118 '', '--git_path', default='git',
119 help='Git executable, defaults to "git".',)
120 option_parser.add_option(
121 '', '--reviewers', default=DEFAULT_REVIEWERS,
122 help=('Comma-separated list of reviewers. Default is "%s".'
123 % DEFAULT_REVIEWERS))
124 option_parser.add_option(
125 '', '--cc', default=DEFAULT_CC_LIST,
126 help=('Comma-separated list of addresses to be carbon-copied.'
127 ' Default is "%s".' % DEFAULT_CC_LIST))
128 57
129 options, arguments = option_parser.parse_args(argv)
130
131 if not options.checkout_path:
132 option_parser.error('Must specify checkout_path.')
133 if not git_utils.git_executable():
134 option_parser.error('Invalid git executable.')
135 if len(arguments) > 1: 58 if len(arguments) > 1:
136 option_parser.error('Extra arguments.') 59 option_parser.error('Extra arguments.')
137 if len(arguments) != 1: 60 if len(arguments) != 1:
138 option_parser.error('Missing Codereview URL.') 61 option_parser.error('Missing issue number.')
139 62
140 message = sys.stdin.read() 63 message = sys.stdin.read()
141 add_codereview_message(arguments[0], message, options.checkout_path, 64 add_codereview_message(int(arguments[0]), message)
142 options.skip_cl_upload, options.verbose,
143 options.reviewers, options.cc)
144 65
145 66
146 if __name__ == '__main__': 67 if __name__ == '__main__':
147 main(sys.argv[1:]) 68 main(sys.argv[1:])
148 69
OLDNEW
« no previous file with comments | « PRESUBMIT.py ('k') | tools/fix_pythonpath.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698