| .gitignore | ||
| .gitmodules | ||
| Dockerfile | ||
| install.sh | ||
| pre-commit | ||
| README.md | ||
| yamllint.yaml | ||
Pouta's GIT hooks
Description
Collection of Git hooks to use in Pouta's repositories. This hooks should be added to new Pouta's repositories. Unless differently agree by the team.
Requirements
The hooks require this tools:
- yamllint
- python
- python venv module (python3-venv in Ubuntu)
- python pip module (python3-pip in Ubuntu)
- puppet-lint
- shellcheck
- jq
Installation
Run ./install -d <DIRECTORY_CONTAINING_YOUR_REPOSITORIES> to add the git configuration for the repository
in the specified directory with the path to the repository hooks. You can add --recursive to do it recursively
to all children of the directory.
You can just run git config --local core.hooksPath ~/src/dev/pouta_git_hooks if the hooks are in that folder.
Uninstallation
For each repository restore or remove the line hooksPath from the core section of the file .git/config.
Usage
When you execute a git command cover by one of these hooks, GIT will execute the hooks before your command. For example (from the Git documentation linked above), "the pre-commit hook is run first, before you even type in a commit message.". If any of the tests fails, you commit won't be completed and the errors will be shown.
You can always do a commit skipping the hook with git commit --no-verify.
Hooks
Pre-commit
This hook will check code basic syntax and style according to some standards.
You can exclude python files from been checked for non-errors by adding a comment in your files with a line starting with (note that there must be a comment/reason for the file to be excluded):
- For Python:
# Pylint-Only-Errors <YOUR COMMENT/REASON> - For Shell scripts:
# ShellCheck-Only-Errors <YOUR COMMENT/REASON> - For Puppet:
# PuppetLint-Only-Errors <YOUR COMMENT/REASON> - For YAML:
# Yamllint-Only-Errors <YOUR COMMENT/REASON>
You can exclude a repository from having Python virtual environments created creating a file or
folder called .no_venv in the root of the repository.
If there is any requirements.txt file and Python files changed and there is no .no_venv file,
the pre-commit will create a virtual environment in the folder venv to install all requirements. Otherwise
Pylint would complaint of any missing Python module imported that is not present in your system.
Types of code/configuration covered
- Python
- Shell scripts
- Ansible
- Puppet
- JSON
- YAML
Security
Be aware of the hooks code, that code will run for each commit in your local machine. Don't add untrusted hooks to your repositories.