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

Side by Side Diff: tools/add_codereview_message.py

Issue 141483011: add_codereview_message script to append messages to a CL (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: linting Created 6 years, 10 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 | « no previous file | tools/git_utils.py » ('j') | tools/git_utils.py » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 #!/usr/bin/python2
2
3 # Copyright 2014 Google Inc.
4 #
5 # Use of this source code is governed by a BSD-style license that can be
6 # found in the LICENSE file.
7
8 """Skia's Chromium DEPS Roll Message Script.
9
10 This script takes a codereview URL as its argument and a (possibly
11 multi-line) message on stdin. It then calls `git cl upload` to append
12 the message to the given codereview issue.
13
14 Usage:
15 echo MESSAGE | %prog -c CHROMIUM_PATH CODEREVIEW_URL
16 or:
17 export CHROMIUM_CHECKOUT_PATH="/path/to/chromium/checkout"
18 %prog CODEREVIEW_URL <<EOF
19 MESSAGE
20 EOF
21 or:
22 %prog --help
23 """
24
25 import collections
26 import optparse
27 import os
28 import sys
29
30 import git_utils
31 import misc_utils
32
33
34 # pylint: disable=I0011,C0103
35 # Class-like object.
36 DepsRollOptions = collections.namedtuple(
37 'DepsRollOptions',
38 ['chromium_path', 'skip_cl_upload', 'verbose',
39 'git_path', 'reviewers', 'cc'])
40
41
42 def add_codereview_message(codereview_url, message, options):
43 """Function that does the meat of the work.
borenet 2014/01/30 14:36:35 This docstring is not informative...
hal.canary 2014/01/30 20:11:02 Done.
44
45 Args:
46 codereview_url: (string) we will extract the issue number from
47 this url.
borenet 2014/01/30 14:36:35 Why not just take an issue number? Asking for the
hal.canary 2014/01/30 20:11:02 As the code is written, it will take either. I'll
48 message: (string) will be passed to `git cl upload -m $MESSAGE`
49 options: (object) a duck-typed object with the following fields:
50 options.skip_cl_upload (boolean): if true, will keep the
51 temporary branch around.
52 options.verbose (boolean): print out details useful for debugging.
53 options.git_path (string): git executable
54 options.reviewers (string): comma-separated list of reviewers
55 options.cc (string): comma-separated list of addresses to be
56 carbon-copied
borenet 2014/01/30 14:36:35 I'd prefer having these as separate arguments. I t
hal.canary 2014/01/30 20:11:02 Done.
57 """
58 git = options.git_path
59 issue = codereview_url.strip('/').split('/')[-1]
60 vsp = misc_utils.VerboseSubprocess(options.verbose)
61 branch_name = 'issue_%s' % issue
62 upstream = 'origin/master'
63
64 with misc_utils.ChangeDir(options.chromium_path, options.verbose):
65 vsp.check_call([git, 'fetch', '-q', 'origin'])
66
67 with git_utils.ChangeGitBranch(
68 git, branch_name, upstream, options.verbose):
69 branch_name = git_utils.git_branch_name(git, options.verbose)
70
71 vsp.check_call([git, 'cl', 'patch', issue])
72 git_upload = [
73 git, 'cl', 'upload', '-t', 'bot report', '-m', message]
74 if options.cc:
75 git_upload.append('--cc=' + options.cc)
76 if options.reviewers:
77 git_upload.append('--reviewers=' + options.reviewers)
78
79 if options.skip_cl_upload:
80 space = ' '
81 print 'You should call:'
82 misc_utils.print_subprocess_args(space, ['cd', os.getcwd()])
83 misc_utils.print_subprocess_args(
84 space, [git, 'checkout', branch_name])
85 misc_utils.print_subprocess_args(space, git_upload)
86 else:
87 vsp.check_call(git_upload)
88 print vsp.check_output([git, 'cl', 'issue'])
89
90 if not options.skip_cl_upload:
91 vsp.check_call([git, 'branch', '-D', branch_name])
92
93
94 DEFAULT_REVIEWERS = ','.join([
95 'rmistry@google.com',
96 'reed@google.com',
97 'bsalomon@google.com',
98 'robertphillips@google.com',
99 ])
100
101
102 DEFAULT_CC_LIST = ','.join([
103 'skia-team@google.com',
104 ])
borenet 2014/01/30 14:36:35 I'd prefer these global variables declared before
hal.canary 2014/01/30 20:11:02 Done.
105
106
107 def main(argv):
108 """main function; see module-level docstring and GetOptionParser help.
109
110 Args:
111 argv: sys.argv[1:]-type argument list.
112 """
113 option_parser = optparse.OptionParser(usage=__doc__)
114 option_parser.add_option(
115 '-c', '--chromium_path',
116 default=os.environ.get('CHROMIUM_CHECKOUT_PATH'),
117 help='Path to local Chromium Git repository checkout,'
118 ' defaults to CHROMIUM_CHECKOUT_PATH if that environment'
119 ' variable is set.')
borenet 2014/01/30 14:36:35 Personally, I think that this script could be usef
hal.canary 2014/01/30 20:11:02 Done.
120 option_parser.add_option(
121 '', '--skip_cl_upload', action='store_true', default=False,
122 help='Skip the cl upload step; useful for testing.')
123 option_parser.add_option(
124 '', '--verbose', action='store_true', dest='verbose', default=False,
125 help='Do not suppress the output from `git cl`.',)
126 option_parser.add_option(
127 '', '--git_path', default='git',
128 help='Git executable, defaults to "git".',)
borenet 2014/01/30 14:36:35 Now that we have a git_utils module, we could add
hal.canary 2014/01/30 20:11:02 Done. git_utils.git_executable()
129 option_parser.add_option(
130 '', '--reviewers', default=DEFAULT_REVIEWERS,
131 help=('Comma-separated list of reviewers. Default is "%s".'
132 % DEFAULT_REVIEWERS))
133 option_parser.add_option(
134 '', '--cc', default=DEFAULT_CC_LIST,
135 help=('Comma-separated list of addresses to be carbon-copied.'
136 ' Default is "%s".' % DEFAULT_CC_LIST))
137
138 options, arguments = option_parser.parse_args(argv)
139
140 if not options.chromium_path:
141 option_parser.error('Must specify chromium_path.')
142 if not git_utils.test_git_executable(options.git_path):
143 option_parser.error('Invalid git executable.')
144 if len(arguments) > 1:
145 option_parser.error('Extra arguments.')
146 if len(arguments) != 1:
147 option_parser.error('Missing Codereview URL.')
148
149 message = sys.stdin.read()
150 add_codereview_message(arguments[0], message, options)
151
152
153 if __name__ == '__main__':
154 main(sys.argv[1:])
155
OLDNEW
« no previous file with comments | « no previous file | tools/git_utils.py » ('j') | tools/git_utils.py » ('J')

Powered by Google App Engine
This is Rietveld 408576698