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

Unified Diff: presubmit_support.py

Issue 12676031: Add PresubmitPromptOrNotify helper. (Closed) Base URL: https://chromium.googlesource.com/chromium/tools/depot_tools.git@master
Patch Set: Address review comments. Created 7 years, 9 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 | « no previous file | tests/presubmit_unittest.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: presubmit_support.py
diff --git a/presubmit_support.py b/presubmit_support.py
index 3239d7b2eb8a2d206e3050449777ca1ed6847340..814d3fc37a0d812bbb2bc977293ffe61113eb6d8 100755
--- a/presubmit_support.py
+++ b/presubmit_support.py
@@ -104,9 +104,12 @@ class PresubmitOutput(object):
class OutputApi(object):
- """This class (more like a module) gets passed to presubmit scripts so that
- they can specify various types of results.
+ """An instance of OutputApi gets passed to presubmit scripts so that they
+ can output various types of results.
"""
+ def __init__(self, is_committing):
+ self.is_committing = is_committing
+
class PresubmitResult(object):
"""Base class for result objects."""
fatal = False
@@ -163,6 +166,12 @@ class OutputApi(object):
"""Just print something to the screen -- but it's not even a warning."""
pass
+ def PresubmitPromptOrNotify(self, *args, **kwargs):
+ """Warn the user when uploading, but only notify if committing."""
+ if self.is_committing:
+ return self.PresubmitNotifyResult(*args, **kwargs)
+ return self.PresubmitPromptWarning(*args, **kwargs)
+
class MailTextResult(PresubmitResult):
"""A warning that should be included in the review request email."""
def __init__(self, *args, **kwargs):
@@ -1020,7 +1029,7 @@ class PresubmitExecuter(object):
else:
function_name = 'CheckChangeOnUpload'
if function_name in context:
- context['__args'] = (input_api, OutputApi())
+ context['__args'] = (input_api, OutputApi(self.committing))
logging.debug('Running %s in %s' % (function_name, presubmit_path))
result = eval(function_name + '(*__args)', context)
logging.debug('Running %s done.' % function_name)
« no previous file with comments | « no previous file | tests/presubmit_unittest.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698