aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJason Monk <jmonk@google.com>2017-11-13 20:13:24 +0000
committerandroid-build-merger <android-build-merger@google.com>2017-11-13 20:13:24 +0000
commitc707e480b68911941b82d23b4deeaf8343a08ccf (patch)
tree7a8af68a187c9b9e37789ee9ac07aed2eddc44e5
parent2e6d1e3202b551342da62f0056f744e9e311e83c (diff)
parent3c136924c0d29c39226dd67f0d43de2e3a2eddb2 (diff)
downloadrepohooks-c707e480b68911941b82d23b4deeaf8343a08ccf.tar.gz
Add support for warning command am: 0886c91f7f
am: 3c136924c0 Change-Id: I51289e08ba0a647561e06770f94b5885bf9ad2c6
-rw-r--r--README.md6
-rwxr-xr-xpre-upload.py36
-rw-r--r--rh/results.py6
3 files changed, 41 insertions, 7 deletions
diff --git a/README.md b/README.md
index f25b979..c2dd55e 100644
--- a/README.md
+++ b/README.md
@@ -220,6 +220,12 @@ These are notes for people updating the `pre-upload.py` hook itself:
* New hooks can be added in `rh/hooks.py`. Be sure to keep the list up-to-date
with the documentation in this file.
+### Warnings
+
+If the return code of a hook is 77, then it is assumed to be a warning. The
+output will be printed to the terminal, but uploading will still be allowed
+without a bypass being required.
+
## TODO/Limitations
* `pylint` should support per-directory pylintrc files.
diff --git a/pre-upload.py b/pre-upload.py
index 86f6da0..80473c1 100755
--- a/pre-upload.py
+++ b/pre-upload.py
@@ -61,6 +61,7 @@ class Output(object):
RUNNING = COLOR.color(COLOR.YELLOW, 'RUNNING')
PASSED = COLOR.color(COLOR.GREEN, 'PASSED')
FAILED = COLOR.color(COLOR.RED, 'FAILED')
+ WARNING = COLOR.color(COLOR.YELLOW, 'WARNING')
def __init__(self, project_name, num_hooks):
"""Create a new Output object for a specified project.
@@ -108,6 +109,17 @@ class Output(object):
print(error, file=sys.stderr)
self.success = False
+ def hook_warning(self, hook_name, warning):
+ """Print a warning.
+
+ Args:
+ hook_name: name of the hook.
+ warning: warning string.
+ """
+ status_line = '[%s] %s' % (self.WARNING, hook_name)
+ rh.terminal.print_status_line(status_line, print_newline=True)
+ print(warning, file=sys.stderr)
+
def finish(self):
"""Print repohook summary."""
status_line = '[%s] repohooks for %s %s' % (
@@ -125,19 +137,26 @@ def _process_hook_results(results):
Returns:
error output if an error occurred, otherwise None
+ warning output if an error occurred, otherwise None
"""
if not results:
- return None
+ return (None, None)
- ret = ''
+ error_ret = ''
+ warning_ret = ''
for result in results:
if result:
+ ret = ''
if result.files:
ret += ' FILES: %s' % (result.files,)
lines = result.error.splitlines()
ret += '\n'.join(' %s' % (x,) for x in lines)
+ if result.is_warning():
+ warning_ret += ret
+ else:
+ error_ret += ret
- return ret or None
+ return (error_ret or None, warning_ret or None)
def _get_project_config():
@@ -275,10 +294,13 @@ def _run_project_hooks(project_name, proj_dir=None,
for name, hook in hooks:
output.hook_start(name)
hook_results = hook(project, commit, desc, diff)
- error = _process_hook_results(hook_results)
- if error:
- ret = False
- output.hook_error(name, error)
+ (error, warning) = _process_hook_results(hook_results)
+ if error or warning:
+ if warning:
+ output.hook_warning(name, warning)
+ if error:
+ ret = False
+ output.hook_error(name, error)
for result in hook_results:
if result.fixup_func:
fixup_func_list.append((name, commit,
diff --git a/rh/results.py b/rh/results.py
index 8fa956f..7ce48d6 100644
--- a/rh/results.py
+++ b/rh/results.py
@@ -58,6 +58,9 @@ class HookResult(object):
"""Python 2/3 glue."""
return self.__bool__()
+ def is_warning(self):
+ return False
+
class HookCommandResult(HookResult):
"""A single hook result based on a CommandResult."""
@@ -71,3 +74,6 @@ class HookCommandResult(HookResult):
def __bool__(self):
return self.result.returncode not in (None, 0)
+
+ def is_warning(self):
+ return self.result.returncode == 77