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
# Core (check + baseline commands)
pip install codeowners-coverage
# With AI-powered suggestions (requires Ollama)
pip install codeowners-coverage[suggest]
Usage
Check coverage
codeowners-coverage check
Generate baseline
codeowners-coverage baseline
Suggest CODEOWNERS entries (AI-powered)
Requires the
[suggest]extra:pip install codeowners-coverage[suggest]
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 (all features)
uv pip install -e ".[dev,suggest]"
# 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
Metadata
Release files for codeowners-coverage 0.3.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| codeowners_coverage-0.3.1.tar.gz | 38.8 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| codeowners_coverage-0.3.1-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 67.7 kB
Release files / codeowners_coverage-0.3.1.tar.gz
| Download URL | codeowners_coverage-0.3.1.tar.gz |
|---|---|
| Size | 38.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
7f3166339cac867b34c6dd466254aaf4e552ce94e0c8a96fa21843a8d8807b7b
|
|
BLAKE2b-256 checksum How to use checksums |
6d651d3c9d47f3f31b716b607f525ab1f05f9d7554c1151330b03a455b245a45
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.14.3
|
Release files / codeowners_coverage-0.3.1-py3-none-any.whl
| Download URL | codeowners_coverage-0.3.1-py3-none-any.whl |
|---|---|
| Size | 28.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
8d4244cad9127a6429cab65043bcac3f190c58dc56317d4999aea6987d2eacb0
|
|
BLAKE2b-256 checksum How to use checksums |
2c217dd67da316193a954bb0294f03839dd28499232fab6b002e4f6a3d4d0282
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.14.3
|