Commit 9de9ec66 authored by tandrii's avatar tandrii Committed by Commit bot

git cl try: Trigger CQ Dry Run by default.

If bots are specified manually on command line OR in PRESUBMIT.py,
then old behavior remains, namely triggering just those bots.

Otherwise, git cl try will now trigger CQ Dry Run. This is a good
default and also resolves several bugs:

 * https://crbug.com/581150 where git cl try used to load cq.cfg
   from infra/config, but that's not always correct for all projects.

 * https://crbug.com/625697 where even if cq.cfg is in default location.
   it might be outdated.

 * https://crbug.com/585237 where git cl try would ignore special
   in CL description CQ_INCLUDE_TRYBOTS, which is processed by CQ,
   but not git cl try.

BUG=625697,585237,581150
R=sergiyb@chromium.org,emso@chromium.org

Review-Url: https://codereview.chromium.org/2147563003
parent d9e5ce51
......@@ -4550,28 +4550,8 @@ def CMDtry(parser, args):
options.verbose,
sys.stdout)
if not options.bot:
# Get try masters from cq.cfg if any.
# TODO(tandrii): some (but very few) projects store cq.cfg in different
# location.
cq_cfg = os.path.join(change.RepositoryRoot(),
'infra', 'config', 'cq.cfg')
if os.path.exists(cq_cfg):
masters = {}
cq_masters = commit_queue.get_master_builder_map(
cq_cfg, include_experimental=False, include_triggered=False)
for master, builders in cq_masters.iteritems():
for builder in builders:
# Skip presubmit builders, because these will fail without LGTM.
masters.setdefault(master, {})[builder] = ['defaulttests']
if masters:
print('Loaded default bots from CQ config (%s)' % cq_cfg)
return masters
else:
print('CQ config exists (%s) but has no try bots listed' % cq_cfg)
if not options.bot:
parser.error('No default try builder to try, use --bot')
return {}
builders_and_tests = {}
# TODO(machenbach): The old style command-line options don't support
......@@ -4596,6 +4576,28 @@ def CMDtry(parser, args):
return {options.master: builders_and_tests}
masters = GetMasterMap()
if not masters:
# Default to triggering Dry Run (see http://crbug.com/625697).
if options.verbose:
print('git cl try with no bots now defaults to CQ Dry Run.')
try:
cl.SetCQState(_CQState.DRY_RUN)
print('scheduled CQ Dry Run on %s' % cl.GetIssueURL())
return 0
except KeyboardInterrupt:
raise
except:
print('WARNING: failed to trigger CQ Dry Run.\n'
'Either:\n'
' * your project has no CQ\n'
' * you don\'t have permission to trigger Dry Run\n'
' * bug in this code (see stack trace below).\n'
'Consider specifying which bots to trigger manually '
'or asking your project owners for permissions '
'or contacting Chrome Infrastructure team at '
'https://www.chromium.org/infra\n\n')
# Still raise exception so that stack trace is printed.
raise
for builders in masters.itervalues():
if any('triggered' in b for b in builders):
......@@ -4749,7 +4751,7 @@ def CMDset_commit(parser, args):
state = _CQState.COMMIT
if not cl.GetIssue():
parser.error('Must upload the issue first')
cl._codereview_impl.SetCQState(state)
cl.SetCQState(state)
return 0
......
......@@ -1668,6 +1668,44 @@ class TestGitCl(TestCase):
]
self.assertEqual(0, git_cl.main(['issue', '0']))
def test_git_cl_try_default(self):
self.mock(git_cl.Changelist, 'GetChange',
lambda _, *a: (
self._mocked_call(['GetChange']+list(a))))
self.mock(git_cl.presubmit_support, 'DoGetTryMasters',
lambda *_, **__: (
self._mocked_call(['DoGetTryMasters'])))
self.mock(git_cl.presubmit_support, 'DoGetTrySlaves',
lambda *_, **__: (
self._mocked_call(['DoGetTrySlaves'])))
self.mock(git_cl._RietveldChangelistImpl, 'SetCQState',
lambda _, s: self._mocked_call(['SetCQState', s]))
self.calls = [
((['git', 'symbolic-ref', 'HEAD'],), 'feature'),
((['git', 'config', 'branch.feature.rietveldissue'],), '123'),
((['git', 'config', 'rietveld.autoupdate'],), ''),
((['git', 'config', 'rietveld.server'],),
'https://codereview.chromium.org'),
((['git', 'config', 'branch.feature.rietveldserver'],), ''),
((['git', 'config', 'branch.feature.merge'],), 'feature'),
((['git', 'config', 'branch.feature.remote'],), 'origin'),
((['get_or_create_merge_base', 'feature', 'feature'],),
'fake_ancestor_sha'),
((['GetChange', 'fake_ancestor_sha', None], ),
git_cl.presubmit_support.GitChange(
'', '', '', '', '', '', '', '')),
((['git', 'rev-parse', '--show-cdup'],), '../'),
((['DoGetTryMasters'], ), None),
((['DoGetTrySlaves'], ), None),
((['SetCQState', git_cl._CQState.DRY_RUN], ), None),
]
out = StringIO.StringIO()
self.mock(git_cl.sys, 'stdout', out)
self.assertEqual(0, git_cl.main(['try']))
self.assertEqual(
out.getvalue(),
'scheduled CQ Dry Run on https://codereview.chromium.org/123\n')
def _common_GerritCommitMsgHookCheck(self):
self.mock(git_cl.sys, 'stdout', StringIO.StringIO())
self.mock(git_cl.os.path, 'abspath',
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment