-
Notifications
You must be signed in to change notification settings - Fork 0
feat: Trivy Pre-Commit Hook with Security Scanning #2
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
Conversation
Implement a comprehensive Python-based pre-commit hook that integrates Trivy security scanning to detect vulnerabilities in codebases before commits are finalized. Features: - Core Trivy scanning hook with configurable severity levels - Support for multiple scanners (vuln, misconfig, secret, license) - Flexible output formats (table, json, sarif, etc.) - Custom configuration via trivy.yaml and .trivyignore - Comprehensive test suite with 93% coverage - GitHub Actions CI/CD workflow for automated testing and linting - Complete documentation with usage examples Technical implementation: - Python 3.9+ with type hints and modern practices - Command-line argument parsing with argparse - Subprocess-based Trivy execution with error handling - Hatchling-based build system - Black formatter and Pylint for code quality - Pytest with coverage reporting Closes #1
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR implements a comprehensive Python-based pre-commit hook that integrates Trivy security scanning into the development workflow, enabling automatic vulnerability detection before commits are finalized.
Key Changes:
- Complete Trivy pre-commit hook implementation with configurable security scanning options
- Comprehensive test suite achieving 93% code coverage with 26 passing tests
- Full project infrastructure including CI/CD, documentation, and configuration examples
Reviewed Changes
Copilot reviewed 12 out of 12 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
pre_commit_hooks/trivy_scan.py |
Core hook implementation with Trivy integration, argument parsing, and scan execution |
pre_commit_hooks/__init__.py |
Package initialization with version metadata |
tests/test_trivy_scan.py |
Comprehensive test suite covering installation checks, argument parsing, scan execution, and main function |
tests/conftest.py |
Pytest fixtures for mocking Trivy installation and subprocess calls |
tests/__init__.py |
Test package initialization |
pyproject.toml |
Project configuration with dependencies, build system, and tool settings |
.pre-commit-hooks.yaml |
Pre-commit framework hook configuration |
.github/workflows/ci.yml |
GitHub Actions CI/CD workflow for testing across Python 3.9-3.12 |
README.md |
Comprehensive documentation with installation, usage, and configuration examples |
trivy.yaml.example |
Example Trivy configuration file with common settings |
.trivyignore.example |
Example file for ignoring specific CVEs |
.pylintrc |
Pylint configuration for code quality checks |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
Signed-off-by: Mehdi Bechiri <cebidhem@pm.me>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
Copilot reviewed 12 out of 12 changed files in this pull request and generated 1 comment.
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
Summary
This PR implements a comprehensive Python-based pre-commit hook that integrates Trivy security scanning to detect vulnerabilities in codebases before commits are finalized.
Key Features
Implementation Details
Core Components:
pre_commit_hooks/trivy_scan.py- Main hook implementation with full Trivy integration.pre-commit-hooks.yaml- Pre-commit framework configurationConfiguration Options:
Development Tools:
Files Changed
Testing
All validation checks passed:
Documentation
Test Plan
trivy-scan --help)python -m pre_commit_hooks.trivy_scan --help)Closes
Closes #1