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 4532 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
4543 # Fall back to deprecated method: get try slaves from PRESUBMIT.py files. | 4543 # Fall back to deprecated method: get try slaves from PRESUBMIT.py files. |
4544 options.bot = presubmit_support.DoGetTrySlaves( | 4544 options.bot = presubmit_support.DoGetTrySlaves( |
4545 change, | 4545 change, |
4546 change.LocalPaths(), | 4546 change.LocalPaths(), |
4547 settings.GetRoot(), | 4547 settings.GetRoot(), |
4548 None, | 4548 None, |
4549 None, | 4549 None, |
4550 options.verbose, | 4550 options.verbose, |
4551 sys.stdout) | 4551 sys.stdout) |
4552 | 4552 |
4553 if not options.bot: | |
4554 # Get try masters from cq.cfg if any. | |
4555 # TODO(tandrii): some (but very few) projects store cq.cfg in different | |
4556 # location. | |
4557 cq_cfg = os.path.join(change.RepositoryRoot(), | |
4558 'infra', 'config', 'cq.cfg') | |
4559 if os.path.exists(cq_cfg): | |
4560 masters = {} | |
4561 cq_masters = commit_queue.get_master_builder_map( | |
4562 cq_cfg, include_experimental=False, include_triggered=False) | |
4563 for master, builders in cq_masters.iteritems(): | |
4564 for builder in builders: | |
4565 # Skip presubmit builders, because these will fail without LGTM. | |
4566 masters.setdefault(master, {})[builder] = ['defaulttests'] | |
4567 if masters: | |
4568 print('Loaded default bots from CQ config (%s)' % cq_cfg) | |
4569 return masters | |
4570 else: | |
4571 print('CQ config exists (%s) but has no try bots listed' % cq_cfg) | |
4572 | |
4573 if not options.bot: | 4553 if not options.bot: |
4574 parser.error('No default try builder to try, use --bot') | 4554 return {} |
4575 | 4555 |
4576 builders_and_tests = {} | 4556 builders_and_tests = {} |
4577 # TODO(machenbach): The old style command-line options don't support | 4557 # TODO(machenbach): The old style command-line options don't support |
4578 # multiple try masters yet. | 4558 # multiple try masters yet. |
4579 old_style = filter(lambda x: isinstance(x, basestring), options.bot) | 4559 old_style = filter(lambda x: isinstance(x, basestring), options.bot) |
4580 new_style = filter(lambda x: isinstance(x, tuple), options.bot) | 4560 new_style = filter(lambda x: isinstance(x, tuple), options.bot) |
4581 | 4561 |
4582 for bot in old_style: | 4562 for bot in old_style: |
4583 if ':' in bot: | 4563 if ':' in bot: |
4584 parser.error('Specifying testfilter is no longer supported') | 4564 parser.error('Specifying testfilter is no longer supported') |
4585 elif ',' in bot: | 4565 elif ',' in bot: |
4586 parser.error('Specify one bot per --bot flag') | 4566 parser.error('Specify one bot per --bot flag') |
4587 else: | 4567 else: |
4588 builders_and_tests.setdefault(bot, []) | 4568 builders_and_tests.setdefault(bot, []) |
4589 | 4569 |
4590 for bot, tests in new_style: | 4570 for bot, tests in new_style: |
4591 builders_and_tests.setdefault(bot, []).extend(tests) | 4571 builders_and_tests.setdefault(bot, []).extend(tests) |
4592 | 4572 |
4593 # Return a master map with one master to be backwards compatible. The | 4573 # Return a master map with one master to be backwards compatible. The |
4594 # master name defaults to an empty string, which will cause the master | 4574 # master name defaults to an empty string, which will cause the master |
4595 # not to be set on rietveld (deprecated). | 4575 # not to be set on rietveld (deprecated). |
4596 return {options.master: builders_and_tests} | 4576 return {options.master: builders_and_tests} |
4597 | 4577 |
4598 masters = GetMasterMap() | 4578 masters = GetMasterMap() |
4579 if not masters: | |
4580 # Default to triggering Dry Run (see http://crbug.com/625697). | |
4581 if options.verbose: | |
4582 print('git cl try with no bots now defaults to CQ Dry Run.') | |
4583 try: | |
4584 cl.SetCQState(_CQState.DRY_RUN) | |
4585 print('scheduled CQ Dry Run on %s' % cl.GetIssueURL()) | |
4586 return 0 | |
4587 except KeyboardInterrupt: | |
4588 raise | |
4589 except: | |
Paweł Hajdan Jr.
2016/07/13 09:55:46
I'd usually catch Exception here, with no need the
tandrii(chromium)
2016/07/13 09:57:51
the purpose of explicitly mentioning Keyboard inte
| |
4590 print('WARNING: failed to trigger CQ Dry Run.\n' | |
4591 'Either:\n' | |
4592 ' * your project has no CQ\n' | |
4593 ' * you don\'t have permission to trigger Dry Run\n' | |
4594 ' * bug in this code (see stack trace below).\n' | |
4595 'Consider specifying which bots to trigger manually ' | |
4596 'or asking your project owners for permissions ' | |
4597 'or contacting Chrome Infrastructure team at ' | |
4598 'https://www.chromium.org/infra\n\n') | |
4599 # Still raise exception so that stack trace is printed. | |
4600 raise | |
4599 | 4601 |
4600 for builders in masters.itervalues(): | 4602 for builders in masters.itervalues(): |
4601 if any('triggered' in b for b in builders): | 4603 if any('triggered' in b for b in builders): |
4602 print('ERROR You are trying to send a job to a triggered bot. This type ' | 4604 print('ERROR You are trying to send a job to a triggered bot. This type ' |
4603 'of bot requires an\ninitial job from a parent (usually a builder).' | 4605 'of bot requires an\ninitial job from a parent (usually a builder).' |
4604 ' Instead send your job to the parent.\n' | 4606 ' Instead send your job to the parent.\n' |
4605 'Bot list: %s' % builders, file=sys.stderr) | 4607 'Bot list: %s' % builders, file=sys.stderr) |
4606 return 1 | 4608 return 1 |
4607 | 4609 |
4608 patchset = cl.GetMostRecentPatchset() | 4610 patchset = cl.GetMostRecentPatchset() |
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
4742 | 4744 |
4743 cl = Changelist(auth_config=auth_config) | 4745 cl = Changelist(auth_config=auth_config) |
4744 if options.clear: | 4746 if options.clear: |
4745 state = _CQState.CLEAR | 4747 state = _CQState.CLEAR |
4746 elif options.dry_run: | 4748 elif options.dry_run: |
4747 state = _CQState.DRY_RUN | 4749 state = _CQState.DRY_RUN |
4748 else: | 4750 else: |
4749 state = _CQState.COMMIT | 4751 state = _CQState.COMMIT |
4750 if not cl.GetIssue(): | 4752 if not cl.GetIssue(): |
4751 parser.error('Must upload the issue first') | 4753 parser.error('Must upload the issue first') |
4752 cl._codereview_impl.SetCQState(state) | 4754 cl.SetCQState(state) |
4753 return 0 | 4755 return 0 |
4754 | 4756 |
4755 | 4757 |
4756 def CMDset_close(parser, args): | 4758 def CMDset_close(parser, args): |
4757 """Closes the issue.""" | 4759 """Closes the issue.""" |
4758 auth.add_auth_options(parser) | 4760 auth.add_auth_options(parser) |
4759 options, args = parser.parse_args(args) | 4761 options, args = parser.parse_args(args) |
4760 auth_config = auth.extract_auth_config_from_options(options) | 4762 auth_config = auth.extract_auth_config_from_options(options) |
4761 if args: | 4763 if args: |
4762 parser.error('Unrecognized args: %s' % ' '.join(args)) | 4764 parser.error('Unrecognized args: %s' % ' '.join(args)) |
(...skipping 340 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
5103 if __name__ == '__main__': | 5105 if __name__ == '__main__': |
5104 # These affect sys.stdout so do it outside of main() to simplify mocks in | 5106 # These affect sys.stdout so do it outside of main() to simplify mocks in |
5105 # unit testing. | 5107 # unit testing. |
5106 fix_encoding.fix_encoding() | 5108 fix_encoding.fix_encoding() |
5107 setup_color.init() | 5109 setup_color.init() |
5108 try: | 5110 try: |
5109 sys.exit(main(sys.argv[1:])) | 5111 sys.exit(main(sys.argv[1:])) |
5110 except KeyboardInterrupt: | 5112 except KeyboardInterrupt: |
5111 sys.stderr.write('interrupted\n') | 5113 sys.stderr.write('interrupted\n') |
5112 sys.exit(1) | 5114 sys.exit(1) |
OLD | NEW |