diff --git a/tools_webrtc/autoroller/roll_deps.py b/tools_webrtc/autoroller/roll_deps.py index aaf49fc4da..9cd601db88 100755 --- a/tools_webrtc/autoroller/roll_deps.py +++ b/tools_webrtc/autoroller/roll_deps.py @@ -403,13 +403,31 @@ def _LocalCommit(commit_msg, dry_run): _RunCommand(['git', 'commit', '-m', commit_msg]) -def _UploadCL(dry_run, skip_cq=False): +def ShouldUseCQ(skip_cq, cq_over, current_cr_rev, new_cr_rev): + if skip_cq: + return 0 + if (new_cr_rev - current_cr_rev) < cq_over: + return 1 + return 2 + + +def _UploadCL(dry_run, commit_queue=2): + """Upload the committed changes as a changelist to Gerrit. + + commit_queue: + - 2: Submit to commit queue. + - 1: Commit queue dry run. + - 0: Skip CQ, upload only. + """ logging.info('Uploading CL...') if not dry_run: cmd = ['git', 'cl', 'upload', '-f', '--gerrit'] - if not skip_cq: + if commit_queue >= 2: logging.info('Sending the CL to the CQ...') cmd.extend(['--use-commit-queue', '--send-mail']) + elif commit_queue >= 1: + logging.info('Starting CQ dry run...') + cmd.extend(['--cq-dry-run']) _RunCommand(cmd, extra_env={'EDITOR': 'true', 'SKIP_GCE_AUTH_FOR_GIT': '1'}) @@ -432,8 +450,12 @@ def main(): default=False, help=('Ignore if the current branch is not master or if there ' 'are uncommitted changes (default: %(default)s).')) - p.add_argument('--skip-cq', action='store_true', default=False, - help='Skip sending the CL to the CQ (default: %(default)s)') + grp = p.add_mutually_exclusive_group() + grp.add_argument('--skip-cq', action='store_true', default=False, + help='Skip sending the CL to the CQ (default: %(default)s)') + grp.add_argument('--cq-over', type=int, default=1, + help=('Commit queue dry run if the revision difference ' + 'is below this number (default: %(default)s)')) p.add_argument('-v', '--verbose', action='store_true', default=False, help='Be extra verbose in printing of log messages.') opts = p.parse_args() @@ -481,7 +503,9 @@ def main(): logging.info("No DEPS changes detected, skipping CL creation.") else: _LocalCommit(commit_msg, opts.dry_run) - _UploadCL(opts.dry_run, opts.skip_cq) + commit_queue = ShouldUseCQ(opts.skip_cq, opts.cq_over, + current_cr_rev, new_cr_rev) + _UploadCL(opts.dry_run, commit_queue) return 0 diff --git a/tools_webrtc/autoroller/unittests/roll_deps_test.py b/tools_webrtc/autoroller/unittests/roll_deps_test.py index 5c48a86c16..369feea7db 100755 --- a/tools_webrtc/autoroller/unittests/roll_deps_test.py +++ b/tools_webrtc/autoroller/unittests/roll_deps_test.py @@ -20,7 +20,7 @@ PARENT_DIR = os.path.join(SCRIPT_DIR, os.pardir) sys.path.append(PARENT_DIR) import roll_deps from roll_deps import CalculateChangedDeps, GetMatchingDepsEntries, \ - ParseDepsDict, ParseLocalDepsFile, UpdateDepsFile + ParseDepsDict, ParseLocalDepsFile, UpdateDepsFile, ShouldUseCQ TEST_DATA_VARS = { @@ -140,6 +140,17 @@ class TestRollChromiumRevision(unittest.TestCase): self.assertEquals(changed_deps[1].new_rev, BUILDTOOLS_NEW_REV) +class TestShouldUseCQ(unittest.TestCase): + def testSkip(self): + self.assertEquals(ShouldUseCQ(True, 99, 500000, 500100), 0) + + def testDryRun(self): + self.assertEquals(ShouldUseCQ(False, 101, 500000, 500100), 1) + + def testSubmit(self): + self.assertEquals(ShouldUseCQ(False, 100, 500000, 500100), 2) + + def _SetupGitLsRemoteCall(cmd_fake, url, revision): cmd = ['git', 'ls-remote', url, revision] cmd_fake.AddExpectation(cmd, _returns=(revision, None))