diff options
author | Josh Gao <jmgao@google.com> | 2016-09-27 00:14:26 +0000 |
---|---|---|
committer | android-build-merger <android-build-merger@google.com> | 2016-09-27 00:14:26 +0000 |
commit | f9cff6d9d0cbc03bac361e066a58daafd7138170 (patch) | |
tree | 71794da91edbaa3455ff714bdbe33e1a7518b743 | |
parent | cba08cc0b0e9630f70ded1c57388285d86dbc49d (diff) | |
parent | 877882f81e1b83714d90d1cfa43f00f2729d05b8 (diff) | |
download | repohooks-f9cff6d9d0cbc03bac361e066a58daafd7138170.tar.gz |
hooks: use the provided name for custom hooks. am: 409f5cdc5b am: b4b3b8fdd9
am: 877882f81e
Change-Id: I970c25b32e0fad693605d0e3598ae6519d1eacac
-rw-r--r-- | README.md | 3 | ||||
-rw-r--r-- | rh/config.py | 6 | ||||
-rw-r--r-- | rh/hooks.py | 22 | ||||
-rw-r--r-- | rh/results.py | 3 |
4 files changed, 20 insertions, 14 deletions
@@ -89,7 +89,8 @@ A few environment variables are set so scripts don't need to discover things. This section allows for completely arbitrary hooks to run on a per-repo basis. The key can be any name (as long as the syntax is valid), as can the program -that is executed. +that is executed. The key is used as the name of the hook for reporting purposes, +so it should be at least somewhat descriptive. ``` [Hook Scripts] diff --git a/rh/config.py b/rh/config.py index 1fc6ca6..1c2a7d6 100644 --- a/rh/config.py +++ b/rh/config.py @@ -155,13 +155,15 @@ class PreSubmitConfig(object): def callable_hooks(self): """Yield a callback for each hook to be executed (custom & builtin).""" for hook in self.custom_hooks: - options = rh.hooks.HookOptions(self.custom_hook(hook), + options = rh.hooks.HookOptions(hook, + self.custom_hook(hook), self.tool_paths) yield functools.partial(rh.hooks.check_custom, options=options) for hook in self.builtin_hooks: - options = rh.hooks.HookOptions(self.builtin_hook_option(hook), + options = rh.hooks.HookOptions(hook, + self.builtin_hook_option(hook), self.tool_paths) yield functools.partial(rh.hooks.BUILTIN_HOOKS[hook], options=options) diff --git a/rh/hooks.py b/rh/hooks.py index 0a67280..b77ee42 100644 --- a/rh/hooks.py +++ b/rh/hooks.py @@ -36,13 +36,15 @@ import rh.utils class HookOptions(object): """Holder class for hook options.""" - def __init__(self, args, tool_paths): + def __init__(self, name, args, tool_paths): """Initialize. Args: + name: The name of the hook. args: The override commandline arguments for the hook. tool_paths: A dictionary with tool names to paths. """ + self.name = name self._args = args self._tool_paths = tool_paths @@ -168,9 +170,9 @@ def _get_build_os_name(): return 'linux-x86' -def _check_cmd(project, commit, cmd, **kwargs): +def _check_cmd(hook_name, project, commit, cmd, **kwargs): """Runs |cmd| and returns its result as a HookCommandResult.""" - return [rh.results.HookCommandResult(project, commit, + return [rh.results.HookCommandResult(hook_name, project, commit, _run_command(cmd, **kwargs))] @@ -184,7 +186,8 @@ def get_helper_path(tool): def check_custom(project, commit, _desc, diff, options=None, **kwargs): """Run a custom hook.""" - return _check_cmd(project, commit, options.args((), diff), **kwargs) + return _check_cmd(options.name, project, commit, options.args((), diff), + **kwargs) def check_checkpatch(project, commit, _desc, diff, options=None): @@ -192,7 +195,8 @@ def check_checkpatch(project, commit, _desc, diff, options=None): tool = get_helper_path('checkpatch.pl') cmd = ([tool, '-', '--root', project.dir] + options.args(('--ignore=GERRIT_CHANGE_ID',), diff)) - return _check_cmd(project, commit, cmd, input=rh.git.get_patch(commit)) + return _check_cmd('checkpatch.pl', project, commit, cmd, + input=rh.git.get_patch(commit)) def check_clang_format(project, commit, _desc, diff, options=None): @@ -203,7 +207,7 @@ def check_clang_format(project, commit, _desc, diff, options=None): cmd = ([tool, '--clang-format', clang_format, '--git-clang-format', git_clang_format] + options.args(('--style', 'file', '--commit', commit), diff)) - return _check_cmd(project, commit, cmd) + return _check_cmd('clang-format', project, commit, cmd) def check_commit_msg_bug_field(project, commit, desc, _diff, options=None): @@ -317,7 +321,7 @@ def check_cpplint(project, commit, _desc, diff, options=None): cpplint = options.tool_path('cpplint') cmd = [cpplint] + options.args(('${PREUPLOAD_FILES}',), filtered) - return _check_cmd(project, commit, cmd) + return _check_cmd('cpplint', project, commit, cmd) def check_gofmt(project, commit, _desc, diff, options=None): @@ -370,7 +374,7 @@ def check_pylint(project, commit, _desc, diff, options=None): get_helper_path('pylint.py'), '--executable-path', pylint, ] + options.args(('${PREUPLOAD_FILES}',), filtered) - return _check_cmd(project, commit, cmd) + return _check_cmd('pylint', project, commit, cmd) def check_xmllint(project, commit, _desc, diff, options=None): @@ -414,7 +418,7 @@ def check_xmllint(project, commit, _desc, diff, options=None): # XXX: Should we use python's XML libs instead? cmd = ['xmllint'] + options.args(('${PREUPLOAD_FILES}',), filtered) - return _check_cmd(project, commit, cmd) + return _check_cmd('xmllint', project, commit, cmd) # Hooks that projects can opt into. diff --git a/rh/results.py b/rh/results.py index f9421ef..ecf7f50 100644 --- a/rh/results.py +++ b/rh/results.py @@ -47,8 +47,7 @@ class HookResult(object): class HookCommandResult(HookResult): """A single hook result based on a CommandResult.""" - def __init__(self, project, commit, result, files=()): - hook = os.path.basename(result.cmd[0]) + def __init__(self, hook, project, commit, result, files=()): HookResult.__init__(self, hook, project, commit, result.error if result.error else result.output, files=files) |