diff --git a/git_cl.py b/git_cl.py index 74ece83abb..954ab206b0 100755 --- a/git_cl.py +++ b/git_cl.py @@ -2055,15 +2055,6 @@ class Changelist(object): if not options.private and not options.no_autocc and not self.GetIssue( ): ccs = self.GetCCList().split(',') - if len(ccs) > 100: - lsc = ( - 'https://chromium.googlesource.com/chromium/src/+/HEAD/docs/' - 'process/lsc/lsc_workflow.md') - print('WARNING: This will auto-CC %s users.' % len(ccs)) - print('LSC may be more appropriate: %s' % lsc) - print( - 'You can also use the --no-autocc flag to disable auto-CC.') - confirm_or_exit(action='continue') # Add ccs from the --cc flag. if options.cc: @@ -3120,13 +3111,6 @@ class Changelist(object): if not options.private and not options.no_autocc and not self.GetIssue( ): cc = self.GetCCList().split(',') - if len(cc) > 100: - lsc = ('https://chromium.googlesource.com/chromium/src/+/HEAD/docs/' - 'process/lsc/lsc_workflow.md') - print('WARNING: This will auto-CC %s users.' % len(cc)) - print('LSC may be more appropriate: %s' % lsc) - print('You can also use the --no-autocc flag to disable auto-CC.') - confirm_or_exit(action='continue') # Add cc's from the --cc flag. if options.cc: cc.extend(options.cc) diff --git a/presubmit_canned_checks.py b/presubmit_canned_checks.py index 57cbace25a..8c2cc28270 100644 --- a/presubmit_canned_checks.py +++ b/presubmit_canned_checks.py @@ -270,6 +270,20 @@ def CheckCorpLinksInFiles(input_api, output_api, source_file_filter=None): return [] +def CheckLargeScaleChange(input_api, output_api): + """Checks if the change should go through the LSC process.""" + size = len(input_api.AffectedFiles()) + if size <= 100: + return [] + return [ + output_api.PresubmitPromptWarning( + f'This change contains {size} files.\n' + 'Consider using the LSC (large scale change) process.\n' + 'See https://chromium.googlesource.com/chromium/src/+/HEAD/docs/process/lsc/lsc_workflow.md.' # pylint: disable=line-too-long + ) + ] + + def GetCppLintFilters(lint_filters=None): filters = OFF_UNLESS_MANUALLY_ENABLED_LINT_FILTERS[:] if lint_filters is None: @@ -1709,6 +1723,9 @@ def PanProjectChecks(input_api, results.extend( input_api.canned_checks.CheckCorpLinksInFiles( input_api, output_api, source_file_filter=sources)) + snapshot("checking large scale change") + results.extend( + input_api.canned_checks.CheckLargeScaleChange(input_api, output_api)) if input_api.is_committing: if global_checks: diff --git a/tests/presubmit_unittest.py b/tests/presubmit_unittest.py index a510df36b1..de9026b710 100755 --- a/tests/presubmit_unittest.py +++ b/tests/presubmit_unittest.py @@ -2035,6 +2035,33 @@ class CannedChecksUnittest(PresubmitTestsBase): 'chromium.git.corp.google.com', None, presubmit.OutputApi.PresubmitPromptWarning) + def testCannedCheckLargeScaleChange(self): + input_api = self.MockInputApi( + presubmit.Change('foo', 'foo1', self.fake_root_dir, None, 0, 0, + None), False) + affected_files = [] + for i in range(100): + affected_file = mock.MagicMock(presubmit.GitAffectedFile) + affected_file.LocalPath.return_value = f'foo{i}.cc' + affected_files.append(affected_file) + input_api.AffectedFiles = lambda **_: affected_files + + # Don't warn if less than or equal to 100 files. + results = presubmit_canned_checks.CheckLargeScaleChange( + input_api, presubmit.OutputApi) + self.assertEqual(len(results), 0) + + # Warn if greater than 100 files. + affected_files.append('bar.cc') + + results = presubmit_canned_checks.CheckLargeScaleChange( + input_api, presubmit.OutputApi) + self.assertEqual(len(results), 1) + result = results[0] + self.assertEqual(result.__class__, + presubmit.OutputApi.PresubmitPromptWarning) + self.assertIn("large scale change", result.json_format()['message']) + def testCheckChangeHasNoStrayWhitespace(self): self.ContentTest( lambda x, y, z: presubmit_canned_checks.