This example demonstrates how to use giton in a testing environment with Docker integration. It shows how giton can be integrated into CI/CD pipelines and local development workflows.
- Docker
- Docker Compose
cd examples/testing
docker-compose up --buildThis will:
- Build a Docker image with giton installed
- Initialize a git repository with giton hooks
- Run giton policies and tests
- Show the results
# Build the Docker image
docker build -t giton-test .
# Run the container
docker run -it --rm giton-test
# Or run with volume mount for local testing
docker run -it --rm -v $(pwd)/test-repo:/app/test-repo giton-test- Running giton policies before tests
- Failing tests when policy violations are found
- Generating test reports with policy findings
- Isolated testing environment
- Reproducible test runs
- Easy CI/CD integration
- Pre-commit hooks running in Docker
- Policy evaluation before commits
- Automated quality checks
examples/testing/
├── Dockerfile # Docker image definition
├── docker-compose.yml # Docker Compose configuration
├── test_giton_integration.py # pytest tests
├── sample_project/ # Sample Python project
│ ├── src/
│ │ └── example.py
│ └── tests/
│ └── test_example.py
└── README.md
# Run all tests
docker-compose run app pytest
# Run specific test
docker-compose run app pytest test_giton_integration.py::test_pre_commit_policy
# Run with coverage
docker-compose run app pytest --cov=src# Install giton
pip install -e ../../../
# Initialize giton in the sample project
cd sample_project
giton init
# Run tests with giton
giton hook pre-commit
pytestname: Test with Giton
on: [push, pull_request]
jobs:
test:
runs-on: ubuntu-latest
container: python:3.13
steps:
- uses: actions/checkout@v3
- name: Install giton
run: pip install giton
- name: Initialize giton
run: giton init
- name: Run giton policies
run: giton policy check pre-commit
- name: Run tests
run: pytesttest:
image: python:3.13
before_script:
- pip install giton
- giton init
script:
- giton policy check pre-commit
- pytestCreate .giton/config.yaml in your repository:
policies:
commit_message:
enabled: true
pattern: "^(feat|fix|docs|style|refactor|test|chore):"
test_coverage:
enabled: true
min_coverage: 80
code_quality:
enabled: true
tools: ["ruff", "mypy"]Make sure the .git directory is properly mounted and has correct permissions.
Ensure giton is installed in the Docker image or add the source directory to PYTHONPATH.
Verify that .giton/config.yaml exists and is properly formatted.