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 and Gerrit.""" | 8 """A git-command for integrating reviews on Rietveld and Gerrit.""" |
9 | 9 |
10 from __future__ import print_function | 10 from __future__ import print_function |
(...skipping 377 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
388 buildbucket_put_url, | 388 buildbucket_put_url, |
389 'PUT', | 389 'PUT', |
390 body=json.dumps(batch_req_body), | 390 body=json.dumps(batch_req_body), |
391 headers={'Content-Type': 'application/json'} | 391 headers={'Content-Type': 'application/json'} |
392 ) | 392 ) |
393 print_text.append('To see results here, run: git cl try-results') | 393 print_text.append('To see results here, run: git cl try-results') |
394 print_text.append('To see results in browser, run: git cl web') | 394 print_text.append('To see results in browser, run: git cl web') |
395 print('\n'.join(print_text)) | 395 print('\n'.join(print_text)) |
396 | 396 |
397 | 397 |
398 def fetch_try_jobs(auth_config, changelist, options): | 398 def fetch_try_jobs(auth_config, changelist, buildbucket_host, |
399 patchset=None): | |
399 """Fetches try jobs from buildbucket. | 400 """Fetches try jobs from buildbucket. |
400 | 401 |
401 Returns a map from build id to build info as a dictionary. | 402 Returns a map from build id to build info as a dictionary. |
402 """ | 403 """ |
403 rietveld_url = settings.GetDefaultServerUrl() | 404 assert buildbucket_host |
404 rietveld_host = urlparse.urlparse(rietveld_url).hostname | 405 assert changelist.GetIssue(), 'CL must be uploaded first' |
405 authenticator = auth.get_authenticator_for_host(rietveld_host, auth_config) | 406 assert changelist.GetCodereviewServer(), 'CL must be uploaded first' |
407 patchset = patchset or changelist.GetMostRecentPatchset() | |
408 assert patchset, 'CL must be uploaded first' | |
409 | |
410 codereview_url = changelist.GetCodereviewServer() | |
411 codereview_host = urlparse.urlparse(codereview_url).hostname | |
412 authenticator = auth.get_authenticator_for_host(codereview_host, auth_config) | |
406 if authenticator.has_cached_credentials(): | 413 if authenticator.has_cached_credentials(): |
407 http = authenticator.authorize(httplib2.Http()) | 414 http = authenticator.authorize(httplib2.Http()) |
408 else: | 415 else: |
409 print('Warning: Some results might be missing because %s' % | 416 print('Warning: Some results might be missing because %s' % |
410 # Get the message on how to login. | 417 # Get the message on how to login. |
411 (auth.LoginRequiredError(rietveld_host).message,)) | 418 (auth.LoginRequiredError(codereview_host).message,)) |
412 http = httplib2.Http() | 419 http = httplib2.Http() |
413 | 420 |
414 http.force_exception_to_status_code = True | 421 http.force_exception_to_status_code = True |
415 | 422 |
416 buildset = 'patch/rietveld/{hostname}/{issue}/{patch}'.format( | 423 buildset = 'patch/{codereview}/{hostname}/{issue}/{patch}'.format( |
417 hostname=rietveld_host, | 424 codereview='gerrit' if changelist.IsGerrit() else 'rietveld', |
425 hostname=codereview_host, | |
418 issue=changelist.GetIssue(), | 426 issue=changelist.GetIssue(), |
419 patch=options.patchset) | 427 patch=patchset) |
420 params = {'tag': 'buildset:%s' % buildset} | 428 params = {'tag': 'buildset:%s' % buildset} |
421 | 429 |
422 builds = {} | 430 builds = {} |
423 while True: | 431 while True: |
424 url = 'https://{hostname}/_ah/api/buildbucket/v1/search?{params}'.format( | 432 url = 'https://{hostname}/_ah/api/buildbucket/v1/search?{params}'.format( |
425 hostname=options.buildbucket_host, | 433 hostname=buildbucket_host, |
426 params=urllib.urlencode(params)) | 434 params=urllib.urlencode(params)) |
427 content = _buildbucket_retry('fetching try jobs', http, url, 'GET') | 435 content = _buildbucket_retry('fetching try jobs', http, url, 'GET') |
428 for build in content.get('builds', []): | 436 for build in content.get('builds', []): |
429 builds[build['id']] = build | 437 builds[build['id']] = build |
430 if 'next_cursor' in content: | 438 if 'next_cursor' in content: |
431 params['start_cursor'] = content['next_cursor'] | 439 params['start_cursor'] = content['next_cursor'] |
432 else: | 440 else: |
433 break | 441 break |
434 return builds | 442 return builds |
435 | 443 |
(...skipping 4395 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
4831 auth.add_auth_options(parser) | 4839 auth.add_auth_options(parser) |
4832 options, args = parser.parse_args(args) | 4840 options, args = parser.parse_args(args) |
4833 if args: | 4841 if args: |
4834 parser.error('Unrecognized args: %s' % ' '.join(args)) | 4842 parser.error('Unrecognized args: %s' % ' '.join(args)) |
4835 | 4843 |
4836 auth_config = auth.extract_auth_config_from_options(options) | 4844 auth_config = auth.extract_auth_config_from_options(options) |
4837 cl = Changelist(auth_config=auth_config) | 4845 cl = Changelist(auth_config=auth_config) |
4838 if not cl.GetIssue(): | 4846 if not cl.GetIssue(): |
4839 parser.error('Need to upload first') | 4847 parser.error('Need to upload first') |
4840 | 4848 |
4841 if not options.patchset: | 4849 patchset = options.patchset |
4842 options.patchset = cl.GetMostRecentPatchset() | 4850 if not patchset: |
4843 if options.patchset and options.patchset != cl.GetPatchset(): | 4851 patchset = cl.GetMostRecentPatchset() |
4844 print( | 4852 if not patchset: |
4845 '\nWARNING Mismatch between local config and server. Did a previous ' | 4853 parser.error('Codereview doesn\'t know about issue %s. ' |
4846 'upload fail?\ngit-cl try always uses latest patchset from rietveld. ' | 4854 'No access to issue or wrong issue number?\n' |
4847 'Continuing using\npatchset %s.\n' % options.patchset) | 4855 'Either upload first, or pass --patchset explicitely' % |
4856 cl.GetIssue()) | |
4857 | |
4858 if patchset != cl.GetPatchset(): | |
4859 print('WARNING: Mismatch between local config and server. Did a previous ' | |
4860 'upload fail?\n' | |
4861 'By default, git cl try uses latest patchset from codereview.\n' | |
4862 'Continuing using patchset %s.\n' % patchset) | |
4848 try: | 4863 try: |
4849 jobs = fetch_try_jobs(auth_config, cl, options) | 4864 jobs = fetch_try_jobs(auth_config, cl, options.buildbucket_host, patchset) |
4850 except BuildbucketResponseException as ex: | 4865 except BuildbucketResponseException as ex: |
4851 print('Buildbucket error: %s' % ex) | 4866 print('Buildbucket error: %s' % ex) |
4852 return 1 | 4867 return 1 |
4853 except Exception as e: | |
tandrii(chromium)
2016/10/06 13:21:10
there is no value in this, stack trace is printed
| |
4854 stacktrace = (''.join(traceback.format_stack()) + traceback.format_exc()) | |
4855 print('ERROR: Exception when trying to fetch try jobs: %s\n%s' % | |
4856 (e, stacktrace)) | |
4857 return 1 | |
4858 if options.json: | 4868 if options.json: |
4859 write_try_results_json(options.json, jobs) | 4869 write_try_results_json(options.json, jobs) |
4860 else: | 4870 else: |
4861 print_try_jobs(options, jobs) | 4871 print_try_jobs(options, jobs) |
4862 return 0 | 4872 return 0 |
4863 | 4873 |
4864 | 4874 |
4865 @subcommand.usage('[new upstream branch]') | 4875 @subcommand.usage('[new upstream branch]') |
4866 def CMDupstream(parser, args): | 4876 def CMDupstream(parser, args): |
4867 """Prints or sets the name of the upstream branch, if any.""" | 4877 """Prints or sets the name of the upstream branch, if any.""" |
(...skipping 432 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
5300 if __name__ == '__main__': | 5310 if __name__ == '__main__': |
5301 # These affect sys.stdout so do it outside of main() to simplify mocks in | 5311 # These affect sys.stdout so do it outside of main() to simplify mocks in |
5302 # unit testing. | 5312 # unit testing. |
5303 fix_encoding.fix_encoding() | 5313 fix_encoding.fix_encoding() |
5304 setup_color.init() | 5314 setup_color.init() |
5305 try: | 5315 try: |
5306 sys.exit(main(sys.argv[1:])) | 5316 sys.exit(main(sys.argv[1:])) |
5307 except KeyboardInterrupt: | 5317 except KeyboardInterrupt: |
5308 sys.stderr.write('interrupted\n') | 5318 sys.stderr.write('interrupted\n') |
5309 sys.exit(1) | 5319 sys.exit(1) |
OLD | NEW |