This directory contains git hooks to ensure code quality and consistency in the project.
Runs before each commit to ensure:
- Go code is properly formatted (
gofmt) - Basic linting with
go vet - No trailing whitespace in files
- Files end with newlines
- YAML files are valid
Runs before each push to ensure:
- All tests pass (
go test) - Build is successful (
go build) - CRD manifests are up-to-date (
make manifests) - Generated code is current (
make generate) - Full linting passes (if
golangci-lintis available)
Validates commit messages follow conventional commit format:
<type>[(scope)]: <description>
[optional body]
[optional footer]
Valid types: feat, fix, docs, style, refactor, test, chore, ci
Examples:
- ✅
feat: add matcher field to AlertReaction CRD - ✅
fix(controller): resolve memory leak in alert processing - ✅
docs: update installation instructions - ❌
updated readme(missing type) - ❌
Fix bug(type should be lowercase)
./scripts/setup-hooks.shThis script will:
- Copy all hooks to
.git/hooks/ - Make them executable
- Verify installation
# Copy hooks
cp scripts/hooks/* .git/hooks/
# Make executable
chmod +x .git/hooks/pre-commit .git/hooks/pre-push .git/hooks/commit-msgTest your hooks without committing:
./scripts/test-hooks.shThis will verify:
- All hooks are installed and executable
- Commit message validation works correctly
- Required tools are available
- Basic code quality checks pass
In exceptional cases, you can skip hooks:
# Skip pre-commit hook
git commit --no-verify -m "emergency fix"
# Skip pre-push hook
git push --no-verifyNote: Use --no-verify sparingly and only for genuine emergencies.
go- Go compilergofmt- Go code formatter
golangci-lint- Advanced Go lintermake- Build automation
Install golangci-lint:
# macOS
brew install golangci-lint
# Linux/Windows
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin- Check formatting:
gofmt -w . - Run tests:
go test ./... - Check for issues:
go vet ./...
- Update manifests:
make manifests - Update generated code:
make generate - Run full test suite:
make test
Ensure your commit message follows the format:
type(scope): description
If you need to bypass hooks temporarily:
mv .git/hooks .git/hooks.disabled
# ... do your work ...
mv .git/hooks.disabled .git/hooksEdit the hooks to add file patterns to skip:
# In pre-commit hook
if [[ "$file" =~ \.(pb|generated)\.go$ ]]; then
continue # Skip generated files
fiEdit scripts/hooks/commit-msg to change the validation regex or add new rules.
Edit the hook files to add new validation steps. Remember to:
- Keep checks fast for pre-commit
- Save expensive operations for pre-push
- Provide clear error messages
When onboarding new team members:
- Have them run
./scripts/setup-hooks.sh - Verify with
./scripts/test-hooks.sh - Walk through the conventional commit format
- Ensure they have required tools installed
The hooks will ensure consistent code quality across the entire team automatically.