Comprehensive GitHub PR health scoring with AI-powered analysis
Project description
PR Health Score Agent
A sophisticated CLI-based agent that calculates health scores for GitHub Pull Requests using multiple factors and AI-powered analysis.
๐ Features
-
Enhanced Interactive Menu System (v2.0.1)
- โจ๏ธ Number-based selection: Press 1, 2, 3 instead of typing
- ๐ฏ Multi-select support: Configure multiple AI providers at once (e.g.,
1,2,3) - โ Smart defaults: Default values shown in brackets, just press Enter
- ๐ Consistent UX: All menus and prompts follow the same pattern
- See MENU_GUIDE.md for detailed usage
-
Comprehensive 13-Category Scoring System (100 Points)
-
Part A: PR Review Criteria (70 points)
- ๐ Size (5): Multi-factor analysis (lines, files, commits, distribution)
- ๐งช Test Quality (10): Coverage % + delta analysis
- ๐ Commit Quality (5): Conventional commits + best practices
- ๐ Review Quality (5): Reviewers, approvals, discussion engagement
- ๐ Security (10): Secrets detection + vulnerability scanning
- ๐ฏ Code Quality (8): Complexity, duplication, function length
- ๐ Code Style (3): Linting errors, formatting adherence
- ๐ฆ Dependencies (4): Vulnerability detection via Dependabot API
- ๐ CHANGELOG (5): Updates, versioning, breaking changes
- ๐ฅ CODEOWNERS (3): File coverage, ownership clarity
- โ ๏ธ Breaking Changes (5): Detection + documentation quality
- ๐ Documentation (7): PR description, README, inline docs
-
Part B: Impact Analysis (30 points) - AI-Powered
- ๐ Complexity (10): Architectural complexity, cognitive load
- ๐ฏ Impact Scope (10): Business impact + technical reach
- โก Performance (10): Execution time, resource usage, database impact
-
-
AI-Powered Deep Analysis (Multiple Providers)
- ๐ค Google Gemini 2.0 Flash (Recommended - Free tier, fast)
- โ๏ธ AWS Bedrock Claude 3.5 Haiku (Supports SSO, API Key, IAM Role)
- ๐ฎ OpenAI GPT-4o-mini (Cost-effective)
- Analyzes actual code changes (not just filenames)
- Complexity assessment with cognitive load analysis
- Business and technical impact evaluation
- Performance implications (database, API, resource usage)
- Automated quality recommendations with score improvement values
-
Dependency Security Scanning
- ๐ Uses GitHub Dependabot API (FREE - no GHAS license required)
- Detects vulnerabilities: Critical, High, Moderate, Low
- Supports 9+ ecosystems: npm, pip, maven, gradle, composer, bundler, cargo, go, nuget
- Auto-scoring: Critical = 0pts, High = -20pts, Moderate = -8pts, Low = -3pts
-
Automated Actions
- ๐ก Recommendations Engine: Shows actionable improvements with point values
- ๐ซ Merge Blocking: Prevents merges below score threshold (70/100)
- ๐ท๏ธ Label Management: Auto-labels PRs based on health category
- ๐ฌ PR Comments: Posts detailed health reports with all 13 categories
- โ Status Checks: Creates commit status checks
๐ Prerequisites
- Python 3.8+
- GitHub Personal Access Token with
repoandsecurity_eventsscope - AI Provider (Optional, choose one or more):
- Google Gemini API Key (Recommended - free tier, fast)
- AWS Bedrock (API Key, SSO, or IAM Role)
- OpenAI API Key
๐ Comprehensive Scoring System
The PR Review Agent uses a 100-point comprehensive scoring system with 13 evaluation categories:
Part A: PR Review Criteria (70 points)
| Category | Max Points | Evaluation Criteria | Data Source |
|---|---|---|---|
| ๐ Size | 5 | Lines changed, files modified, commits count, distribution | Enhanced Size Analyzer |
| ๐งช Test Quality | 10 | Coverage %, coverage delta, test file ratio | Coverage Analyzer |
| ๐ Commit Quality | 5 | Conventional commits, message quality, issue references | Commit Analyzer |
| ๐ Review Quality | 5 | Reviewers count, approvals, review comments | PR Metadata |
| ๐ Security | 10 | Secrets detection, vulnerability scanning, insecure patterns | Security Scanner + Dependabot |
| ๐ฏ Code Quality | 8 | Complexity, duplication, long functions, maintainability | Code Quality Analyzer |
| ๐ Code Style | 3 | Linting errors, formatting adherence | Style Checkers |
| ๐ฆ Dependencies | 4 | Vulnerabilities (Critical/High/Moderate/Low) | GitHub Dependabot API |
| ๐ CHANGELOG | 5 | File exists, updated, versioning, breaking changes | CHANGELOG Analyzer |
| ๐ฅ CODEOWNERS | 3 | File coverage %, ownership clarity | CODEOWNERS Analyzer |
| โ ๏ธ Breaking Changes | 5 | Detection, documentation, migration guide | Breaking Changes Analyzer |
| ๐ Documentation | 7 | PR description, title, testing info, context | Documentation Analyzer |
Part B: Impact Analysis (30 points) - AI-Powered
| Category | Max Points | Evaluation Criteria | AI Provider |
|---|---|---|---|
| ๐ Complexity | 10 | Architectural complexity, cognitive load, design patterns | Bedrock/Gemini/OpenAI |
| ๐ฏ Impact Scope | 10 | Business impact, technical reach, affected modules | Bedrock/Gemini/OpenAI |
| โก Performance | 10 | Execution time, resource usage, database queries, API calls | Bedrock/Gemini/OpenAI |
Score Categories
| Score Range | Category | Merge Decision |
|---|---|---|
| 90-100 | ๐ Excellent | โ Merge Recommended |
| 80-89 | โ Good | โ Merge Recommended |
| 70-79 | โ ๏ธ Needs Improvement | โ Merge Allowed |
| 60-69 | ๐ด Poor | ๐ซ Merge Blocked |
| 0-59 | ๐ซ Critical Issues | ๐ซ Merge Blocked |
Dependency Vulnerability Scoring
| Severity | Point Deduction | Auto-Fail |
|---|---|---|
| Critical | N/A | โ Score = 0 |
| High | -20 per vulnerability | No |
| Moderate | -8 per vulnerability | No |
| Low | -3 per vulnerability | No |
๐ฆ Installation
For End Users (No Code Access Required)
# Install directly from GitHub
pip install git+https://github.com/LTIM-Digital-Engineering/PR-Review-Agent.git
# With AWS Bedrock support
pip install "git+https://github.com/LTIM-Digital-Engineering/PR-Review-Agent.git#egg=pr-health-agent[bedrock]"
After installation, use these commands:
# Interactive application
pr-health-app
# Setup wizard
pr-health-interactive
# Direct analysis
pr-health owner/repo 123 --ai-analysis --post-comment
๐ See INSTALLATION.md for complete installation guide
For Developers (Local Development)
๐ Quick Start
1. Navigate to Directory
cd C:\Users\10691618\Desktop\PR-Review-Agent
2. Install Dependencies
pip install -r requirements.txt
For AWS Bedrock support (optional):
pip install boto3
3. Run Unified Application
python app.py
This launches an interactive menu with options for:
- Setup & Configuration - Configure GitHub PAT and AI providers
- Analyze Pull Request - Run comprehensive PR analysis
- Commands Reference - View all available commands
- Exit
4. Alternative: Interactive Setup Wizard
python interactive.py
This wizard will guide you through:
- โ GitHub token setup and validation
- โ AI provider selection (Gemini/Bedrock/OpenAI)
- โ API key validation
- โ Environment variable configuration
5. Direct Command-Line Usage
# Basic analysis
python pr_agent.py owner/repo PR_NUMBER
# With AI analysis
python pr_agent.py owner/repo PR_NUMBER --ai-analysis
# Full analysis with comment posting
python pr_agent.py owner/repo PR_NUMBER --ai-analysis --post-comment
โ๏ธ Configuration
Scoring Weights (config.yaml)
| Category | Weight | What It Measures |
|---|---|---|
| Size | 10% | Lines, files, commits (multi-factor) |
| Commit Quality | 10% | Message quality, conventional commits |
| Test Quality | 20% | Coverage %, test files ratio |
| Review Quality | 20% | Reviewers, approvals, comments |
| Complexity | 15% | AI-powered complexity assessment |
| Security | 15% | Secret scanning, vulnerabilities |
| Code Quality | 5% | Linting, complexity, duplication |
| Documentation | 5% | PR description quality |
PR Size Categories (Multi-Factor)
| Category | Lines | Files | Commits | Score |
|---|---|---|---|---|
| Small | <5 | 1-2 | 1-2 | 100 pts |
| Medium | <10 | 4-5 | โค5 | 85 pts |
| Complex | 15-50 | <10 | โค10 | 70 pts |
| Very Complex | >50 | >10 | >10 | 50 pts |
AI Provider Configuration
Edit config.yaml to configure your AI provider:
ai:
# Gemini (Google)
gemini:
model: "gemini-2.0-flash-lite"
max_tokens: 2000
temperature: 0.3
# Bedrock (AWS)
bedrock:
model_id: "us.anthropic.claude-3-5-haiku-20241022-v1:0"
region: "us-east-1"
auth_method: "api_key" # or 'sso', 'iam_role'
sso_profile: "" # For SSO authentication
# OpenAI
openai:
model: "gpt-4o-mini"
max_tokens: 2000
temperature: 0.3
Environment Variables
Set these in your system or create a .env file:
# Required
GITHUB_TOKEN=ghp_your_github_token
# AI Providers (choose one or more)
GEMINI_API_KEY=your_gemini_api_key
OPENAI_API_KEY=your_openai_api_key
# AWS Bedrock (choose one auth method)
BEDROCK_API_KEY=your_bedrock_key
# OR
AWS_PROFILE=your_sso_profile_name
# OR use default IAM role
# Optional
AI_PROVIDER=gemini # or bedrock, openai
AWS_REGION=us-east-1
๐ Documentation
- AI_PROVIDERS.md - Detailed AI provider setup guide
- config.yaml - Full configuration reference with comments
๐ง Project Structure
PR-Review-Agent/
โโโ app.py # Main unified application entry point
โโโ pr_agent.py # CLI tool for direct PR analysis
โโโ interactive.py # Setup wizard
โ
โโโ pr_collector.py # GitHub API integration
โโโ score_calculator.py # Health score calculation engine
โโโ ai_analyzer.py # Multi-provider AI integration
โโโ security_scanner.py # Security vulnerability scanning
โโโ coverage_analyzer.py # Code coverage analysis
โโโ commit_analyzer.py # Commit quality analysis
โโโ code_quality_analyzer.py # Code quality metrics
โโโ comment_generator.py # PR comment formatting
โโโ merge_controller.py # Merge blocking logic
โ
โโโ config.yaml # Configuration file
โโโ requirements.txt # Python dependencies
โโโ .env.example # Environment template
โ
โโโ AI_PROVIDERS.md # AI provider setup guide
๐ก๏ธ Security & Dependency Scanning
Security Scanner Features
The security scanner detects:
- Secrets: GitHub tokens, AWS keys, API keys, private keys, SSH keys
- Credentials: Hardcoded passwords, JWT tokens, OAuth tokens, Stripe keys
- Vulnerabilities: SQL injection patterns, XSS risks, command injection
- Insecure Functions: eval(), exec(), pickle.loads(), md5(), sha1()
- Configuration Issues: Debug mode enabled, insecure SSL settings
Dependency Vulnerability Scanning
Uses GitHub Dependabot API (FREE - no GitHub Advanced Security license required):
- Supported Ecosystems: npm, pip, maven, gradle, composer, bundler, cargo, go, nuget
- Severity Detection: Critical, High, Moderate, Low
- Automated Scoring:
- Critical vulnerabilities = Auto-fail (0 points)
- High severity = -20 points each
- Moderate severity = -8 points each
- Low severity = -3 points each
- Requirements:
- GitHub PAT with
security_eventsscope - Dependabot enabled in repository settings
- GitHub PAT with
๐งช Testing
Validate your setup:
# Check dependencies and configuration
python setup_check.py
# Test Gemini connection
python test_gemini.py
# Test Bedrock connection
python test_bedrock.py
๐ Example Output
๐ COMPREHENSIVE ANALYSIS COMPLETE
======================================================================
Overall Score: 78.5/100
PR Review Criteria: 55.2/70
- PR Structure: 18.5/25
- Code Standards: 20.0/25
- Documentation: 16.7/20
Impact Analysis: 23.3/30
- Complexity: 8.0/10
- Impact Scope: 7.5/10
- Performance: 7.8/10
Category: GOOD
======================================================================
## ๐ Part A: PR Review Criteria (55.2/70)
### 1๏ธโฃ PR Structure & Quality (18.5/25)
๐ **Size** (3.8/5)
Lines: 450 | Files: 12 | Commits: 5
Category: Good - Manageable PR size
๐งช **Test Quality** (7.5/10)
Coverage: 75% | Delta: +5% | Test Files: 4/12
๐ **Commit Quality** (4.2/5)
Conventional: 80% | Issue References: Yes
๐ **Review Quality** (3.0/5)
Reviewers: 2 | Approvals: 1 | Comments: 8
### 2๏ธโฃ Code Quality & Standards (20.0/25)
๐ **Security** (8.5/10)
No secrets detected | 2 moderate vulnerabilities
๐ฏ **Code Quality** (6.5/8)
Complex Functions: 3 | Long Functions: 2
๐
**Code Style** (2.0/3)
Linting: Minor issues
๐ฆ **Dependencies** (3.0/4)
2 vulnerabilities (Moderate)
### 3๏ธโฃ Documentation & Standards (16.7/20)
๐ **CHANGELOG** (4.0/5)
Updated with version and changes
๐ฅ **CODEOWNERS** (2.5/3)
Coverage: 85%
โ ๏ธ **Breaking Changes** (3.2/5)
1 breaking change documented
๐ **Documentation** (7.0/7)
Complete PR description
## ๐ฏ Part B: Impact Analysis (23.3/30)
๐ **Complexity** (8.0/10) - AI Analysis
Level: Moderate
Assessment: Well-structured changes with clear separation of concerns
๐ฏ **Impact Scope** (7.5/10) - AI Analysis
Level: Medium
Affected: Authentication module, 3 API endpoints
โก **Performance** (7.8/10) - AI Analysis
Impact: Neutral to Slight Improvement
Database queries optimized
## ๐ก Recommendations - Score Improvement Opportunities
- **Testing**: Improve test coverage from 75% to at least 80%. **(+2.5 points)**
- **Dependencies**: Update 2 vulnerable dependencies to secure versions. **(+1.0 points)**
- **Security**: Fix moderate vulnerabilities in dependencies. **(+1.5 points)**
- **Code Quality**: Refactor 3 complex functions **(+1.5 points)**
- **CODEOWNERS**: Improve coverage from 85% to 100% **(+0.5 points)**
## โ
Summary
No critical issues detected. Address recommendations for higher score.
---
โ
**Merge Recommended** - Score meets minimum threshold (70)
๐ค Contributing
Contributions welcome! Please ensure:
- Code follows existing style
- Tests pass
- Documentation is updated
๐ License
MIT License - See LICENSE file for details
๐ Support
For issues or questions:
- Check
AI_PROVIDERS.mdfor AI setup - Run
python setup_check.pyto validate setup - Review
config.yamlfor configuration options
๐ฏ Roadmap
- Integration with more CI/CD platforms
- Support for GitLab and Bitbucket
- Custom rule engine for security scanning
- Machine learning-based recommendations
- Web dashboard for analytics
- Test coverage expectations
- Comment templates
๐ป Usage
Interactive Mode
For a guided experience with prompts:
python interactive.py
This will interactively ask you for:
- Repository name
- PR number
- Whether to use AI analysis
- Whether to post comments
- Custom threshold (optional)
Basic Usage
Analyze a PR without AI features:
python pr_agent.py owner/repo 123
With AI Analysis
Enable AI-powered complexity and impact analysis:
python pr_agent.py owner/repo 123 --ai-analysis
Post Comment to PR
Analyze and post results as a PR comment:
python pr_agent.py owner/repo 123 --ai-analysis --post-comment
Full Featured Analysis
Run complete analysis with all features:
python pr_agent.py owner/repo 123 --ai-analysis --post-comment --add-labels
Custom Threshold
Override the minimum passing score:
python pr_agent.py owner/repo 123 --threshold 80
Interactive Mode
For a guided experience with prompts:
python interactive.py
This will interactively ask you for repository, PR number, and analysis options.
CI/CD Integration
Use in CI/CD pipelines (exits with code 1 if score fails):
python pr_agent.py owner/repo 123 --ai-analysis --post-comment --add-labels
if ($LASTEXITCODE -ne 0) {
Write-Host "PR health check failed!"
exit 1
}
๐ฏ Command Line Options
| Option | Description |
|---|---|
repository |
Repository in format owner/repo (required) |
pr_number |
Pull request number (required) |
--config FILE |
Path to config file (default: config.yaml) |
--threshold NUM |
Override minimum passing score |
--ai-analysis |
Enable AI-powered analysis using Bedrock |
--post-comment |
Post health report as PR comment |
--add-labels |
Add health-check labels to PR |
--add-status |
Add commit status check |
--no-block |
Don't exit with error if score fails |
--output FORMAT |
Output format: console, json, or both |
--verbose, -v |
Enable verbose output |
๐ Scoring System
Total Score: 100 points
| Category | Weight | Description |
|---|---|---|
| Size | 20 | Smaller PRs score higher |
| Test Coverage | 25 | Ratio of test files to code files |
| Review Quality | 25 | Number of reviewers, approvals, comments |
| Complexity | 20 | AI-assessed code complexity |
| Description | 10 | PR title and description quality |
Thresholds:
- โ Excellent: 90+ points
- โ Good: 70+ points (default passing)
- โ ๏ธ Needs Improvement: 50-69 points
- โ Poor: < 50 points
๐ง Configuration
The config.yaml file controls all aspects of scoring and behavior:
thresholds:
min_passing_score: 70
excellent_score: 90
weights:
size: 20
test_coverage: 25
review_quality: 25
complexity: 20
description_quality: 10
size_limits:
small: 100
medium: 500
large: 1000
test_coverage:
min_test_files_ratio: 0.3
test_file_patterns:
- "*test*.py"
- "*_test.py"
- "test_*.py"
๐ค AI Features
When --ai-analysis is enabled, the agent uses Amazon Bedrock to:
-
Complexity Analysis
- Evaluates code structure and dependencies
- Identifies risk areas
- Provides refactoring suggestions
-
Impact Assessment
- Determines affected system areas
- Flags breaking changes
- Identifies database/API changes
-
Review Comments
- Generates constructive feedback
- Highlights best practices
- Raises security concerns
๐ Example Output
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ PR HEALTH SCORE REPORT โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
Overall Score: 85/100 (GOOD)
Breakdown:
๐ Size: 18/20
๐งช Test Coverage: 22/25
๐ Review Quality: 20/25
๐ Complexity: 17/20
๐ Description: 8/10
Status: โ
PASS
Threshold: 70
๐ GitHub Token Permissions
Your GitHub token needs these permissions:
repo(full repository access)repo:status(for commit status checks)
๐ CI/CD Integration Examples
GitHub Actions
name: PR Health Check
on:
pull_request:
types: [opened, synchronize, reopened]
jobs:
health-check:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.11'
- name: Install dependencies
run: pip install -r requirements.txt
- name: Run PR Health Check
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
AWS_REGION: ${{ secrets.AWS_REGION }}
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
run: |
python pr_agent.py ${{ github.repository }} ${{ github.event.pull_request.number }} \
--ai-analysis --post-comment --add-labels
Azure DevOps
trigger:
- none
pr:
- main
- develop
pool:
vmImage: 'ubuntu-latest'
steps:
- task: UsePythonVersion@0
inputs:
versionSpec: '3.11'
- script: pip install -r requirements.txt
displayName: 'Install dependencies'
- script: |
python pr_agent.py $(Build.Repository.Name) $(System.PullRequest.PullRequestNumber) \
--ai-analysis --post-comment --add-labels
displayName: 'Run PR Health Check'
env:
GITHUB_TOKEN: $(GITHUB_TOKEN)
AWS_REGION: $(AWS_REGION)
AWS_ACCESS_KEY_ID: $(AWS_ACCESS_KEY_ID)
AWS_SECRET_ACCESS_KEY: $(AWS_SECRET_ACCESS_KEY)
๐ ๏ธ Troubleshooting
Common Issues
Issue: "Error: Missing required environment variables: GITHUB_TOKEN"
- Solution: Create a
.envfile with your GitHub token
Issue: "Failed to fetch PR data: 404"
- Solution: Check repository name format (
owner/repo) and PR number
Issue: "Bedrock API error"
- Solution: Verify AWS credentials and Bedrock access in your region
Issue: "Failed to post comment: 403"
- Solution: Ensure GitHub token has
repopermissions
Debug Mode
Run with verbose output:
python pr_agent.py owner/repo 123 --verbose
๐ฆ Project Structure
PR-Review-Agent/
โโโ pr_agent.py # Main CLI entry point
โโโ pr_collector.py # GitHub API integration
โโโ score_calculator.py # Health score calculation
โโโ bedrock_analyzer.py # Amazon Bedrock AI integration
โโโ comment_generator.py # PR comment formatting
โโโ merge_controller.py # Merge blocking logic
โโโ config.yaml # Configuration file
โโโ requirements.txt # Python dependencies
โโโ .env.example # Environment template
โโโ .gitignore # Git ignore rules
โโโ README.md # This file
๐ค Contributing
Contributions are welcome! Areas for improvement:
- Additional AI model support
- More scoring factors
- Enhanced test detection patterns
- Custom plugin system
๐ License
This project is provided as-is for educational and commercial use.
๐ Acknowledgments
- GitHub API via PyGithub
- Amazon Bedrock for AI capabilities
- Claude 3.5 Sonnet for intelligent analysis
๐ Support
For issues or questions:
- Check the troubleshooting section
- Review configuration settings
- Run with
--verboseflag for detailed logs
Made with โค๏ธ for better Pull Requests
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 pr_health_agent-2.0.1.tar.gz.
File metadata
- Download URL: pr_health_agent-2.0.1.tar.gz
- Upload date:
- Size: 76.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a09f35b0c046060a224b8b87cfe979459aa67921e58b4b28b5ed311dcf623e3d
|
|
| MD5 |
5f6ca1c2e2164bc664231e679f845ea4
|
|
| BLAKE2b-256 |
8793059141b684a5eab71281d153fd66d86ccd2aabb8f303117099235b40232d
|
File details
Details for the file pr_health_agent-2.0.1-py3-none-any.whl.
File metadata
- Download URL: pr_health_agent-2.0.1-py3-none-any.whl
- Upload date:
- Size: 78.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6c8c92752feb5eaa860a2601b205d13e30c7891c38a82742e4793351ae2d416d
|
|
| MD5 |
4fed6e5fb2b8550d4d289766fddb5303
|
|
| BLAKE2b-256 |
8b40d3a5770c82620bd132fca65ab1c2f7295013f34ed12e57581342750834cc
|