Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mandatory hooks #28

Merged
merged 5 commits into from
Sep 13, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
to the previous versions. To update existing installations it requires
overriding the installed git hook by running `autohooks activate --force`.
[#24](https://github.com/greenbone/autohooks/pull/24)
* The installed git hook will fail now if a autohooks plugin can't be executed
e.g. if the import fails. Before these errors were ignored.
[#28](https://github.com/greenbone/autohooks/pull/28)

### Deprecated
### Fixed
Expand Down
18 changes: 12 additions & 6 deletions autohooks/precommit/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def has_precommit_function(plugin):

def has_precommit_parameters(plugin):
signature = inspect.signature(plugin.precommit)
return True if signature.parameters else False
return bool(signature.parameters)


def run():
Expand All @@ -70,14 +70,18 @@ def run():
plugin = load_plugin(name)
if not has_precommit_function(plugin):
error(
'No precommit function found in plugin {}'.format(name)
'No precommit function found in plugin {}. '
'Your autohooks settings may be invalid.'.format(name)
)
return 0
return 1

if has_precommit_parameters(plugin):
retval = plugin.precommit(config=config.get_config())
else:
warning('precommit function without kwargs is deprecated.')
warning(
'precommit function without kwargs is deprecated. '
'Please update {} to a newer version.'.format(name)
)
retval = plugin.precommit()

if retval:
Expand All @@ -86,12 +90,14 @@ def run():
except ImportError as e:
error(
'An error occurred while importing pre-commit '
'hook {}. {}. The hook will be ignored.'.format(name, e)
'hook {}. {}.'.format(name, e)
)
return 1
except Exception as e: # pylint: disable=broad-except
error(
'An error occurred while running pre-commit '
'hook {}. {}. The hook will be ignored.'.format(name, e)
'hook {}. {}.'.format(name, e)
)
return 1

return 0