Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2619)

Unified Diff: depot_tools/presubmit_canned_checks.py

Issue 92087: Create the Next Generation of depot_tools. Eh. (Closed) Base URL: svn://chrome-svn.corp.google.com/chrome/trunk/tools/
Patch Set: Created 11 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « depot_tools/presubmit.py ('k') | depot_tools/profile.xml » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: depot_tools/presubmit_canned_checks.py
===================================================================
--- depot_tools/presubmit_canned_checks.py (revision 0)
+++ depot_tools/presubmit_canned_checks.py (revision 0)
@@ -0,0 +1,102 @@
+#!/usr/bin/env python
+# Copyright (c) 2006-2009 The Chromium Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+"""Generic presubmit checks that can be reused by other presubmit checks."""
+
+
+def CheckChangeHasTestedField(input_api, output_api):
+ """Requires that the changelist have a TESTED= field."""
+ if input_api.change.Tested:
+ return []
+ else:
+ return [output_api.PresubmitError("Changelist must have a TESTED= field.")]
+
+
+def CheckChangeHasQaField(input_api, output_api):
+ """Requires that the changelist have a QA= field."""
+ if input_api.change.QA:
+ return []
+ else:
+ return [output_api.PresubmitError("Changelist must have a QA= field.")]
+
+
+def CheckDoNotSubmitInDescription(input_api, output_api):
+ """Checks that the user didn't add 'DO NOT ' + 'SUBMIT' to the CL description.
+ """
+ keyword = 'DO NOT ' + 'SUBMIT'
+ if keyword in input_api.change.DescriptionText():
+ return [output_api.PresubmitError(
+ keyword + " is present in the changelist description.")]
+ else:
+ return []
+
+
+def CheckDoNotSubmitInFiles(input_api, output_api):
+ """Checks that the user didn't add 'DO NOT ' + 'SUBMIT' to any files."""
+ keyword = 'DO NOT ' + 'SUBMIT'
+ for f, line_num, line in input_api.RightHandSideLines():
+ if keyword in line:
+ text = 'Found ' + keyword + ' in %s, line %s' % (f.LocalPath(), line_num)
+ return [output_api.PresubmitError(text)]
+ return []
+
+
+def CheckDoNotSubmit(input_api, output_api):
+ return (
+ CheckDoNotSubmitInDescription(input_api, output_api) +
+ CheckDoNotSubmitInFiles(input_api, output_api)
+ )
+
+
+def CheckChangeHasNoTabs(input_api, output_api):
+ """Checks that there are no tab characters in any of the text files to be
+ submitted.
+ """
+ for f, line_num, line in input_api.RightHandSideLines():
+ if '\t' in line:
+ return [output_api.PresubmitError(
+ "Found a tab character in %s, line %s" %
+ (f.LocalPath(), line_num))]
+ return []
+
+
+def CheckLongLines(input_api, output_api, maxlen=80):
+ """Checks that there aren't any lines longer than maxlen characters in any of
+ the text files to be submitted.
+ """
+ basename = input_api.basename
+
+ bad = []
+ for f, line_num, line in input_api.RightHandSideLines():
+ if line.endswith('\n'):
+ line = line[:-1]
+ if len(line) > maxlen:
+ bad.append(
+ '%s, line %s, %s chars' %
+ (basename(f.LocalPath()), line_num, len(line)))
+ if len(bad) == 5: # Just show the first 5 errors.
+ break
+
+ if bad:
+ msg = "Found lines longer than %s characters (first 5 shown)." % maxlen
+ return [output_api.PresubmitPromptWarning(msg, items=bad)]
+ else:
+ return []
+
+
+def CheckTreeIsOpen(input_api, output_api, url, closed):
+ """Checks that an url's content doesn't match a regexp that would mean that
+ the tree is closed."""
+ try:
+ connection = input_api.urllib2.urlopen(url)
+ status = connection.read()
+ connection.close()
+ if input_api.re.match(closed, status):
+ long_text = status + '\n' + url
+ return [output_api.PresubmitError("The tree is closed.",
+ long_text=long_text)]
+ except IOError:
+ pass
+ return []
Property changes on: depot_tools\presubmit_canned_checks.py
___________________________________________________________________
Added: svn:executable
+ *
Added: svn:eol-style
+ LF
« no previous file with comments | « depot_tools/presubmit.py ('k') | depot_tools/profile.xml » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698