A smart GitHub webhook service that analyzes PRs to determine test impact
This project has been archived.
The maintainers of this project have marked this project as archived. No new releases are expected.
Project description
Test Impact Analyzer Agent
A smart GitHub webhook service that analyzes pull requests to determine which tests should be run based on code changes. The agent uses AI to understand code dependencies and suggest relevant tests.
Features
- GitHub webhook integration for pull request events
- Intelligent test impact analysis
- Automatic PR comments with analysis results
- Support for multiple programming languages
- Configurable via environment variables
Overall Architecture
+------------------+ +------------------+ +------------------+
| GitHub Webhook |--->| AI Agent |--->| Test Runner |
| (PR Events) | |(Direct Git API) | | (pytest/jest) |
+------------------+ +------------------+ +------------------+
|
+------------------+
| Local Git + |
| GitHub API |
+------------------+
|
+------------------+
| Ollama (Local |
| LLM) |
+------------------+
Prerequisites
- Python 3.8 or higher
- Git 2.x or higher
- Node.js 16+ (for JavaScript/TypeScript projects)
- Docker (optional, for containerized deployment)
- 8GB RAM minimum (16GB recommended for Ollama LLM)
- Operating System:
- Linux (Ubuntu 20.04+, CentOS 7+)
- macOS (Big Sur or newer)
- Windows 10/11 with WSL2
- Disk Space:
- 5GB for base installation
- 4GB+ for Ollama models
- Additional space for analyzed repositories
Installation
Option 1: Install from PyPI (Recommended)
pip install test-impact-analyzer
Option 2: Install from source
- Clone the repository:
git clone https://github.com/uppadhyayraj/test-impact-analyzer-agent.git
cd test-impact-analyzer-agent
- Create and activate a virtual environment:
python -m venv venv
source venv/bin/activate
- Install dependencies:
pip install -r requirements.txt
- Set up environment variables in
.env:
# GitHub token with minimal scope (pull_request:write) for PR comments
GITHUB_TOKEN=your_github_token
# Server configuration (optional, defaults shown)
PORT=5043
HOST=0.0.0.0
DEBUG=False
Note: For security best practices, limit the GitHub token scope to only pull_request:write access. Here's how to create a token with minimal permissions:
- Go to GitHub Settings > Developer Settings > Personal access tokens > Fine-grained tokens
- Click "Generate new token"
- Set token name (e.g., "Test Impact Analyzer")
- Set expiration date
- Select the specific repository you want to analyze
- Under "Repository permissions":
- Pull requests: Access level "Write"
- Leave all other permissions unchecked
- Click "Generate token"
- Copy the token and add it to your
.envfile
This minimal scope is sufficient for posting PR comments while following security best practices.
Ollama Setup
- Install Ollama:
# macOS and Linux
curl -fsSL https://ollama.com/install.sh | sh
# Windows
# Download from https://ollama.com/download/windows
- Pull the required model:
ollama pull qwen2.5-coder:7b
- Update your
.envfile with Ollama configuration:
OLLAMA_HOST=http://localhost:11434
OLLAMA_MODEL=qwen2.5-coder:7b
- Verify Ollama is running:
curl http://localhost:11434/api/health
Note: Ensure Ollama is running before starting the webhook server.
Usage
Running as a Webhook Server
- Start the server:
python src/app.py
- Configure your GitHub repository webhook:
- Webhook URL:
http://your-server:5043/webhook - Events: Select "Pull requests"
- Content type:
application/json
- Webhook URL:
The server will automatically:
- Analyze new pull requests
- Comment with test recommendations
- Update analysis when PRs are updated
Running Webhook Locally
- Install ngrok:
# macOS with Homebrew
brew install ngrok
# Windows with Chocolatey
choco install ngrok
# Or download from https://ngrok.com/download
- Start the webhook server:
python src/github_webhook.py
- In a new terminal, create a public URL with ngrok:
ngrok http 5043
- Configure your GitHub repository webhook:
- Copy the ngrok URL (e.g.,
https://a1b2-c3d4.ngrok.io) - Webhook URL:
https://your-ngrok-url/webhook - Events: Select "Pull requests"
- Content type:
application/json - Secret: Leave empty for testing
- Copy the ngrok URL (e.g.,
Note: The ngrok URL changes each time you restart ngrok. Update your webhook URL in GitHub repository settings accordingly.
Running from Command Line
You can also run the analysis directly on a repository:
python main.py --repo-path /path/to/repo --base-branch main --target-branch feature --format detailed
Options:
--repo-path: Path to the git repository--base-branch: Base branch for comparison (default: main)--target-branch: Target branch with changes--format: Output format (json, markdown, or detailed)--output-file: Optional file to write results to
Configuration
The application can be configured using environment variables or a .env file:
- Create a
.envfile in your project directory:
cp example.env .env
- Edit the
.envfile with your configuration:
# GitHub token with minimal scope (pull_request:write) for PR comments
GITHUB_TOKEN=your_github_token
# Server configuration (optional, defaults shown)
PORT=5043
HOST=0.0.0.0
DEBUG=False
Note: For security best practices, limit the GitHub token scope to only pull_request:write access. Here's how to create a token with minimal permissions:
- Go to GitHub Settings > Developer Settings > Personal access tokens > Fine-grained tokens
- Click "Generate new token"
- Set token name (e.g., "Test Impact Analyzer")
- Set expiration date
- Select the specific repository you want to analyze
- Under "Repository permissions":
- Pull requests: Access level "Write"
- Leave all other permissions unchecked
- Click "Generate token"
- Copy the token and add it to your
.envfile
This minimal scope is sufficient for posting PR comments while following security best practices.
Project Structure
test-impact-analyzer-agent/
├── src/
│ ├── app.py # Main Flask application
│ ├── config.py # Configuration management
│ ├── services/
│ │ ├── github_service.py # GitHub API interactions
│ │ └── repo_service.py # Git repository operations
│ └── utils/
│ └── logging.py # Logging configuration
├── main.py # Test analysis implementation
├── requirements.txt # Project dependencies
└── README.md # Project documentation
Development
- Install dev dependencies:
pip install -r requirements-dev.txt
- Run tests:
pytest
- Run linting:
flake8
Contributing
- Fork the repository
- Create a feature branch
- Commit your changes
- Push to the branch
- Create a Pull Request
License
MIT License - see LICENSE file for details
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 test_impact_analyzer-0.1.1.tar.gz.
File metadata
- Download URL: test_impact_analyzer-0.1.1.tar.gz
- Upload date:
- Size: 21.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e8ead48b34de708b0a3709c2c3df1aa8a4426550f264019a6f0d2951ed8a8b1a
|
|
| MD5 |
55215b956b1e4a4f2534683b67528958
|
|
| BLAKE2b-256 |
55b28b8c8eb468466895729de2d8f6266c6ddd1be6cb0c48b00b5120dd0b2948
|
File details
Details for the file test_impact_analyzer-0.1.1-py3-none-any.whl.
File metadata
- Download URL: test_impact_analyzer-0.1.1-py3-none-any.whl
- Upload date:
- Size: 12.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9e6fe3862a745bc42888a6f737536822e6a1901bbd7c2f8c2520c5c7764b5411
|
|
| MD5 |
7b5fc9dd518ccac0db8a269a4084dda4
|
|
| BLAKE2b-256 |
1d337ab443b6146aff999387636d28e176de3e9b2986665e2ce5fae1325d5f02
|