diff options
author | Jason Monk <jmonk@google.com> | 2017-11-13 20:11:54 +0000 |
---|---|---|
committer | android-build-merger <android-build-merger@google.com> | 2017-11-13 20:11:54 +0000 |
commit | 3c136924c0d29c39226dd67f0d43de2e3a2eddb2 (patch) | |
tree | 7a8af68a187c9b9e37789ee9ac07aed2eddc44e5 | |
parent | 2b84ffa3a1c9491fd07b07043cd69499be879d79 (diff) | |
parent | 0886c91f7f62aa55042699c5a3b6b4629eb79010 (diff) | |
download | repohooks-3c136924c0d29c39226dd67f0d43de2e3a2eddb2.tar.gz |
Add support for warning command
am: 0886c91f7f
Change-Id: I6db604e02f7a7accb136e66cc7de952df62f98f5
-rw-r--r-- | README.md | 6 | ||||
-rwxr-xr-x | pre-upload.py | 36 | ||||
-rw-r--r-- | rh/results.py | 6 |
3 files changed, 41 insertions, 7 deletions
@@ -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 |