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 196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
207 else: | 207 else: |
208 git_set_branch_value('git-find-copies', int(options.find_copies)) | 208 git_set_branch_value('git-find-copies', int(options.find_copies)) |
209 | 209 |
210 print('Using %d%% similarity for rename/copy detection. ' | 210 print('Using %d%% similarity for rename/copy detection. ' |
211 'Override with --similarity.' % options.similarity) | 211 'Override with --similarity.' % options.similarity) |
212 | 212 |
213 return options, args | 213 return options, args |
214 parser.parse_args = Parse | 214 parser.parse_args = Parse |
215 | 215 |
216 | 216 |
217 def _get_properties_from_options(options): | |
Michael Achenbach
2015/09/14 14:18:23
This is partially copied from https://code.google.
| |
218 properties = dict(x.split('=', 1) for x in options.properties) | |
219 for key, val in properties.iteritems(): | |
220 try: | |
221 properties[key] = json.loads(val) | |
222 except ValueError: | |
223 pass # If a value couldn't be evaluated, silently ignore it. | |
tandrii(chromium)
2015/09/14 14:52:22
how about:
s/, silently ignore it./, treat it as a
Michael Achenbach
2015/09/15 08:32:57
Done.
| |
224 return properties | |
225 | |
226 | |
217 def _prefix_master(master): | 227 def _prefix_master(master): |
218 """Convert user-specified master name to full master name. | 228 """Convert user-specified master name to full master name. |
219 | 229 |
220 Buildbucket uses full master name(master.tryserver.chromium.linux) as bucket | 230 Buildbucket uses full master name(master.tryserver.chromium.linux) as bucket |
221 name, while the developers always use shortened master name | 231 name, while the developers always use shortened master name |
222 (tryserver.chromium.linux) by stripping off the prefix 'master.'. This | 232 (tryserver.chromium.linux) by stripping off the prefix 'master.'. This |
223 function does the conversion for buildbucket migration. | 233 function does the conversion for buildbucket migration. |
224 """ | 234 """ |
225 prefix = 'master.' | 235 prefix = 'master.' |
226 if master.startswith(prefix): | 236 if master.startswith(prefix): |
227 return master | 237 return master |
228 return '%s%s' % (prefix, master) | 238 return '%s%s' % (prefix, master) |
229 | 239 |
230 | 240 |
231 def trigger_try_jobs(auth_config, changelist, options, masters, category, | 241 def trigger_try_jobs(auth_config, changelist, options, masters, category): |
232 override_properties=None): | |
Michael Achenbach
2015/09/14 14:18:23
This was added by me a while ago in order to hook
tandrii(chromium)
2015/09/14 14:52:22
Acknowledged.
| |
233 rietveld_url = settings.GetDefaultServerUrl() | 242 rietveld_url = settings.GetDefaultServerUrl() |
234 rietveld_host = urlparse.urlparse(rietveld_url).hostname | 243 rietveld_host = urlparse.urlparse(rietveld_url).hostname |
235 authenticator = auth.get_authenticator_for_host(rietveld_host, auth_config) | 244 authenticator = auth.get_authenticator_for_host(rietveld_host, auth_config) |
236 http = authenticator.authorize(httplib2.Http()) | 245 http = authenticator.authorize(httplib2.Http()) |
237 http.force_exception_to_status_code = True | 246 http.force_exception_to_status_code = True |
238 issue_props = changelist.GetIssueProperties() | 247 issue_props = changelist.GetIssueProperties() |
239 issue = changelist.GetIssue() | 248 issue = changelist.GetIssue() |
240 patchset = changelist.GetMostRecentPatchset() | 249 patchset = changelist.GetMostRecentPatchset() |
250 properties = _get_properties_from_options(options) | |
241 | 251 |
242 buildbucket_put_url = ( | 252 buildbucket_put_url = ( |
243 'https://{hostname}/_ah/api/buildbucket/v1/builds/batch'.format( | 253 'https://{hostname}/_ah/api/buildbucket/v1/builds/batch'.format( |
244 hostname=options.buildbucket_host)) | 254 hostname=options.buildbucket_host)) |
245 buildset = 'patch/rietveld/{hostname}/{issue}/{patch}'.format( | 255 buildset = 'patch/rietveld/{hostname}/{issue}/{patch}'.format( |
246 hostname=rietveld_host, | 256 hostname=rietveld_host, |
247 issue=issue, | 257 issue=issue, |
248 patch=patchset) | 258 patch=patchset) |
249 | 259 |
250 batch_req_body = {'builds': []} | 260 batch_req_body = {'builds': []} |
(...skipping 15 matching lines...) Expand all Loading... | |
266 'master': master, | 276 'master': master, |
267 'patch_project': issue_props['project'], | 277 'patch_project': issue_props['project'], |
268 'patch_storage': 'rietveld', | 278 'patch_storage': 'rietveld', |
269 'patchset': patchset, | 279 'patchset': patchset, |
270 'reason': options.name, | 280 'reason': options.name, |
271 'revision': options.revision, | 281 'revision': options.revision, |
272 'rietveld': rietveld_url, | 282 'rietveld': rietveld_url, |
273 'testfilter': tests, | 283 'testfilter': tests, |
274 }, | 284 }, |
275 } | 285 } |
276 if override_properties: | 286 if properties: |
277 parameters['properties'].update(override_properties) | 287 parameters['properties'].update(properties) |
tandrii(chromium)
2015/09/14 14:52:22
I'm not sure if overriding all properties is a goo
Michael Achenbach
2015/09/15 08:32:57
I'd just like to resemble the buildbucket api, whe
| |
278 if options.clobber: | 288 if options.clobber: |
279 parameters['properties']['clobber'] = True | 289 parameters['properties']['clobber'] = True |
280 batch_req_body['builds'].append( | 290 batch_req_body['builds'].append( |
281 { | 291 { |
282 'bucket': bucket, | 292 'bucket': bucket, |
283 'parameters_json': json.dumps(parameters), | 293 'parameters_json': json.dumps(parameters), |
284 'tags': ['builder:%s' % builder, | 294 'tags': ['builder:%s' % builder, |
285 'buildset:%s' % buildset, | 295 'buildset:%s' % buildset, |
286 'master:%s' % master, | 296 'master:%s' % master, |
287 'user_agent:git_cl_try'] | 297 'user_agent:git_cl_try'] |
(...skipping 2778 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3066 "its waterfall for more info") | 3076 "its waterfall for more info") |
3067 group.add_option( | 3077 group.add_option( |
3068 "-c", "--clobber", action="store_true", default=False, | 3078 "-c", "--clobber", action="store_true", default=False, |
3069 help="Force a clobber before building; e.g. don't do an " | 3079 help="Force a clobber before building; e.g. don't do an " |
3070 "incremental build") | 3080 "incremental build") |
3071 group.add_option( | 3081 group.add_option( |
3072 "--project", | 3082 "--project", |
3073 help="Override which project to use. Projects are defined " | 3083 help="Override which project to use. Projects are defined " |
3074 "server-side to define what default bot set to use") | 3084 "server-side to define what default bot set to use") |
3075 group.add_option( | 3085 group.add_option( |
3086 "-p", "--property", dest="properties", action="append", default=[], | |
3087 help="Specify generic properties in the form -p key1=value1 -p " | |
3088 "key2=value2 etc (buildbucket only). The value will treated as" | |
tandrii(chromium)
2015/09/14 14:52:22
nit: missing "be" : will BE treated
Michael Achenbach
2015/09/15 08:32:57
Done.
| |
3089 "json if decodable, or as string otherwise.") | |
3090 group.add_option( | |
3076 "-n", "--name", help="Try job name; default to current branch name") | 3091 "-n", "--name", help="Try job name; default to current branch name") |
3077 group.add_option( | 3092 group.add_option( |
3078 "--use-rietveld", action="store_true", default=False, | 3093 "--use-rietveld", action="store_true", default=False, |
3079 help="Use Rietveld to trigger try jobs.") | 3094 help="Use Rietveld to trigger try jobs.") |
3080 group.add_option( | 3095 group.add_option( |
3081 "--buildbucket-host", default='cr-buildbucket.appspot.com', | 3096 "--buildbucket-host", default='cr-buildbucket.appspot.com', |
3082 help="Host of buildbucket. The default host is %default.") | 3097 help="Host of buildbucket. The default host is %default.") |
3083 parser.add_option_group(group) | 3098 parser.add_option_group(group) |
3084 auth.add_auth_options(parser) | 3099 auth.add_auth_options(parser) |
3085 options, args = parser.parse_args(args) | 3100 options, args = parser.parse_args(args) |
3086 auth_config = auth.extract_auth_config_from_options(options) | 3101 auth_config = auth.extract_auth_config_from_options(options) |
3087 | 3102 |
3103 if options.use_rietveld and options.properties: | |
3104 parser.error('Properties can only be specified with buildbucket') | |
3105 | |
3106 # Make sure that all properties are prop=value pairs. | |
3107 bad_params = [x for x in options.properties if '=' not in x] | |
3108 if bad_params: | |
3109 parser.error('Got properties with missing "=": %s' % bad_params) | |
3110 | |
3088 if args: | 3111 if args: |
3089 parser.error('Unknown arguments: %s' % args) | 3112 parser.error('Unknown arguments: %s' % args) |
3090 | 3113 |
3091 cl = Changelist(auth_config=auth_config) | 3114 cl = Changelist(auth_config=auth_config) |
3092 if not cl.GetIssue(): | 3115 if not cl.GetIssue(): |
3093 parser.error('Need to upload first') | 3116 parser.error('Need to upload first') |
3094 | 3117 |
3095 props = cl.GetIssueProperties() | 3118 props = cl.GetIssueProperties() |
3096 if props.get('closed'): | 3119 if props.get('closed'): |
3097 parser.error('Cannot send tryjobs for a closed CL') | 3120 parser.error('Cannot send tryjobs for a closed CL') |
(...skipping 460 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3558 if __name__ == '__main__': | 3581 if __name__ == '__main__': |
3559 # These affect sys.stdout so do it outside of main() to simplify mocks in | 3582 # These affect sys.stdout so do it outside of main() to simplify mocks in |
3560 # unit testing. | 3583 # unit testing. |
3561 fix_encoding.fix_encoding() | 3584 fix_encoding.fix_encoding() |
3562 colorama.init() | 3585 colorama.init() |
3563 try: | 3586 try: |
3564 sys.exit(main(sys.argv[1:])) | 3587 sys.exit(main(sys.argv[1:])) |
3565 except KeyboardInterrupt: | 3588 except KeyboardInterrupt: |
3566 sys.stderr.write('interrupted\n') | 3589 sys.stderr.write('interrupted\n') |
3567 sys.exit(1) | 3590 sys.exit(1) |
OLD | NEW |