Measure and enforce CODEOWNERS coverage
Project description
CODEOWNERS Coverage
A tool to measure and enforce CODEOWNERS coverage in your repository.
Prerequisites
- Python 3.9+
- Git repository
- Ollama (for
suggestcommand) - Install from ollama.ai
Ollama Setup (Optional - for AI-powered suggestions)
The suggest command uses a local LLM (Ollama) to intelligently match files to teams based on git history.
- Install Ollama: https://ollama.ai/
- Pull the default model:
ollama pull llama3.2
- Ensure Ollama is running:
ollama serve # Runs on http://localhost:11434
- Verify setup:
just ollama-check # or manually: curl http://localhost:11434
Quick setup:
just ollama-setup # Downloads and configures Ollama model
Installation
pip install codeowners-coverage
Usage
Check coverage
codeowners-coverage check
Generate baseline
codeowners-coverage baseline
Suggest CODEOWNERS entries (AI-powered)
Use local LLM to intelligently suggest team ownership based on git history.
GitHub Token Setup:
- Create a Personal Access Token at https://github.com/settings/tokens
- Choose either:
- Classic Token: Select
read:orgscope - Fine-grained Token: Grant "Read-only" access to "Organization permissions > Members"
- Classic Token: Select
- Export the token:
export GITHUB_TOKEN=ghp_your_token_here
Usage:
# Basic usage (requires GITHUB_TOKEN env var)
# By default, includes both new uncovered files AND baseline files
export GITHUB_TOKEN=ghp_xxxxx
codeowners-coverage suggest
# Or with justfile
just suggest
# Only suggest for new uncovered files (exclude baseline)
codeowners-coverage suggest --no-baseline
# Auto-apply suggestions (creates backup)
codeowners-coverage suggest --apply
# Export as diff for review
codeowners-coverage suggest --format=diff > suggestions.patch
# Configure Ollama model
codeowners-coverage suggest --ollama-model llama3.2
# Adjust directory consolidation threshold
codeowners-coverage suggest --min-coverage 0.9 # 90% consistency required
How it works:
- Finds all uncovered files (both new and baseline by default)
- Analyzes git history to find contributors per file
- Fetches GitHub teams and maps contributors to teams
- Uses local LLM to intelligently suggest ownership
- Consolidates to high-level directory patterns when appropriate
Requirements:
- Ollama running locally (setup:
just ollama-setup) - GitHub Personal Access Token (set via
GITHUB_TOKENenv var)- Token type: Classic PAT or Fine-grained PAT
- Required scope:
read:org(to read organization teams and members) - Token holder must be a member of the organization
- Create at: https://github.com/settings/tokens
- Git repository with commit history
Note: By default, suggestions include both new uncovered files AND baseline files. Use --no-baseline to only suggest for new uncovered files.
Configuration
Create a .codeowners-config.yml file in your repository root:
# Path to CODEOWNERS file
codeowners_path: ".github/CODEOWNERS"
# Path to baseline file
baseline_path: ".github/codeowners-coverage-baseline.txt"
# File patterns to exclude from coverage checking
exclusions:
- "**/__pycache__/**"
- "**/*.pyc"
- "node_modules/**"
- "dist/**"
- ".venv/**"
# Suggestion settings (for 'suggest' command)
github_token: ${GITHUB_TOKEN} # GitHub Personal Access Token (needs read:org scope)
github_org: mycompany # Auto-detected from git remote if omitted
ollama_model: llama3.2 # Ollama model to use
ollama_base_url: http://localhost:11434 # Ollama API endpoint
suggestion_min_coverage: 0.8 # Min % for directory consolidation
suggestion_lookback_commits: 100 # How far back to analyze git history
GitHub Actions Integration
Add a workflow to check CODEOWNERS coverage on pull requests:
name: CODEOWNERS Coverage
on: [pull_request]
jobs:
check:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: '3.11'
- run: pip install codeowners-coverage
- run: codeowners-coverage check
Features
- Pattern Matching: Supports all CODEOWNERS patterns (wildcards, globstars, etc.)
- Baseline Support: Track progress incrementally with a baseline allowlist
- AI-Powered Suggestions: Use local LLM (Ollama) to intelligently suggest CODEOWNERS entries based on git history and team membership
- Smart Consolidation: Automatically groups file-level suggestions into high-level directory patterns
- Configurable: Customize exclusions and paths via YAML config
- Fast: Uses
pathspeclibrary for efficient pattern matching - GitHub Actions Ready: Easy integration with CI/CD pipelines
Development
Using just (recommended)
This project includes a justfile with common development commands:
# Install package in development mode
just install
# Run all tests
just test
# Run tests with coverage report
just test-cov
# Run type checking
just typecheck
# Run linting
just lint
# Run all checks (tests, typecheck, lint)
just check
# Clean build artifacts
just clean
# Build the package
just build
# Or build with uv (faster)
just build-uv
# Format code
just format
# Check Ollama setup
just ollama-check
# Setup Ollama (downloads model)
just ollama-setup
# Run suggest command
just suggest
# Publish to Test PyPI
just publish-test
# Publish to production PyPI
just publish
# Full release workflow
just release
Manual commands
# Install in development mode
uv pip install -e ".[dev]"
# Run tests
pytest tests/ -v
# Run with coverage
pytest tests/ -v --cov
# Build package
python -m build
# Publish to PyPI
twine upload dist/*
License
Apache-2.0
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file codeowners_coverage-0.2.1.tar.gz.
File metadata
- Download URL: codeowners_coverage-0.2.1.tar.gz
- Upload date:
- Size: 37.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
73701d8beebbdc694b679f72de280b6c30c7db929e160ed2f0305b69c6f56756
|
|
| MD5 |
30279fcaeadfc141ada39ee49b64ee5c
|
|
| BLAKE2b-256 |
91e710cc82f39cd1dc5e1945b7e41f05f2a23548a064498e55077353826fb00a
|
File details
Details for the file codeowners_coverage-0.2.1-py3-none-any.whl.
File metadata
- Download URL: codeowners_coverage-0.2.1-py3-none-any.whl
- Upload date:
- Size: 28.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3c120d96fc699bb998774b72b2c506190485bcc8a71e89511ec11297e9fa89cf
|
|
| MD5 |
1fda2b0cf9ea00b2337a54f464cf0d3f
|
|
| BLAKE2b-256 |
74208a0afe3882949ed64f1df611bd56ab2d74f0b6ad0d1e9373168ac982a1df
|