AI PR Insight
AI PR Insight is a powerful command-line tool that extracts and analyzes pull request (PR) comments from GitHub repositories. Using OpenAI's GPT models, it generates actionable checklists and insights to help developers improve their code review process.
Features
- Fetch PR Comments: Extract PR comments from GitHub repositories you have access to.
- AI-Powered Analysis: Use OpenAI's GPT models to analyze comments and generate actionable insights.
- Checklist Generation: Create a checklist of best practices and common issues from PR comments.
- Customizable Filters: Filter comments by year, month, organization, or repository.
- Standalone CLI: Easy-to-use command-line interface for seamless integration into your workflow.
- Summarization: Consolidate and summarize PR analysis results for better insights.
- Verbose Logging: Debug mode available for detailed logs during execution.
Installation
Prerequisites
Ensure you have the following before installation:
- Python 3.8 or higher
- A GitHub personal access token (with
reposcope) - An OpenAI API key
Install via pip
pip3 install ai-pr-insight
Manual Installation
git clone https://github.com/kadivar/ai-pr-insight.git
cd ai-pr-insight
pip3 install -r requirements.txt
Usage
AI PR Insight provides three main commands: fetch, analyze, and summarize.
Fetch PR Comments
To fetch PR comments from a specific year and month within an organization:
ai-pr-insight fetch --year 2024 --month 2 --org my-org --output_file pr-comments.json
You can also filter by a specific GitHub username:
ai-pr-insight fetch --year 2024 --month 2 --username my-user --output_file pr-comments.json
Analyze PR Comments
To analyze PR comments and generate a checklist:
ai-pr-insight analyze --input_file pr-comments.json --output_dir output --batch-size 20 --model-tier premium
batch-size: Number of comments to process in each batch.model-tier: Choose betweeneconomy(GPT-3.5) andpremium(GPT-4).
Summarize PR Analysis Results
To consolidate and summarize analysis results:
ai-pr-insight summarize --input_dir analysis_results --output_dir summary_results --similarity-threshold 0.9 --abstraction-threshold 0.85
similarity-threshold: Defines similarity grouping (range: 0.0 - 1.0).abstraction-threshold: Defines abstraction grouping (range: 0.0 - 1.0).
Enable Debug Mode
For detailed logs, add the --verbose flag:
ai-pr-insight fetch --year 2024 --month 2 --org my-org --output_file pr-comments.json --verbose
Configuration
AI PR Insight uses a .env file for configuration. Place this file in the root directory with the following variables:
GITHUB_TOKEN=your_github_personal_access_token
OPENAI_API_KEY=your_openai_api_key
CACHE_EXPIRATION_MINUTES=120
DEBUG=false
SOURCE_CODE_LINES_OFFSET=3
Environment Variables Explained
GITHUB_TOKEN: Your GitHub personal access token (required).OPENAI_API_KEY: Your OpenAI API key (required).CACHE_EXPIRATION_MINUTES: Cache expiration time in minutes (default: 120).DEBUG: Enable debug mode (default: false).SOURCE_CODE_LINES_OFFSET: Number of lines to include around a code snippet (default: 3).
Running Tests
Run them using:
python3 -m unittest discover tests
Example Outputs
Example PR Comments Output (pr-comments.json)
[
{
"author": "johndoe",
"repository": "surveyanyplace/survey-ui",
"pr_number": 1234,
"pr_title": "Refactor UserProfile component to use hooks [SA-12345]",
"pr_url": "https://github.com/surveyanyplace/survey-ui/pull/1234",
"datetime": "2025-03-15T14:45:22Z",
"message": "A: I think we should also consider adding error handling for the API call in this component.",
"comment_url": "https://github.com/surveyanyplace/survey-ui/pull/1234#discussion_r1987654321",
"permalink": "https://github.com/surveyanyplace/survey-ui/pull/1234#discussion_r1987654321",
"source_code": "import React, { useEffect, useState } from 'react';\nimport axios from 'axios';\n\nconst UserProfile = ({ userId }) => {\n const [user, setUser] = useState(null);\n const [loading, setLoading] = useState(true);\n const [error, setError] = useState(null);\n\n useEffect(() => {\n const fetchUserProfile = async () => {\n try {\n const response = await axios.get(`/api/users/${userId}`);\n setUser(response.data);\n } catch (err) {\n setError(err);\n } finally {\n setLoading(false);\n }\n };\n\n fetchUserProfile();\n }, [userId]);\n\n if (loading) return <div>Loading...</div>;\n if (error) return <div>Error: {error.message}</div>;\n\n return (\n <div>\n <h1>{user.name}</h1>\n <p>{user.email}</p>\n </div>\n );\n};\n\nexport default UserProfile;"
}
]
Example Checklist Output (checklist.md)
# PR Review Checklist
- [ ] Refactor complex functions for better readability.
- [ ] Improve documentation for unclear code sections.
- [ ] Ensure tests cover newly introduced changes.
License
AI PR Insight is licensed under the GNU Affero General Public License (AGPL). See LICENSE for details.
Contributing
Contributions are welcome! Please read our Contributing Guidelines for details on how to get started.
Support
If you encounter any issues or have questions, please open an issue on the GitHub repository.
Made with ❤️ by Mohammadreza Kadivar
Metadata
Release files for ai-pr-insight 1.2.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| ai_pr_insight-1.2.0.tar.gz | 28.4 kB | Without provenance | Details for ai_pr_insight-1.2.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| ai_pr_insight-1.2.0-py3-none-any.whl | Python 3 | none | any | Details for ai_pr_insight-1.2.0-py3-none-any.whl |
Total release size: 52.6 kB
Release files / ai_pr_insight-1.2.0.tar.gz
| Download URL | ai_pr_insight-1.2.0.tar.gz |
|---|---|
| Size | 28.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
1817a610b73a36db9d5929fbadd7b5bcaa174c3e9dd5920387cd823071fdbfa4
|
|
BLAKE2b-256 checksum How to use checksums |
4fcce3a657b5776446769ed16ddb3a10ca4dc76cd2ddbcd8d08b3d0b8dacfdf7
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.10.12
|
Release files / ai_pr_insight-1.2.0-py3-none-any.whl
| Download URL | ai_pr_insight-1.2.0-py3-none-any.whl |
|---|---|
| Size | 24.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
ffb618164ad05219b29982f249bd7fb0d0eb40602f90f4fadc0375cd3317cb4d
|
|
BLAKE2b-256 checksum How to use checksums |
2c16340ad7f207ca856ada3a1a70b7e2af67950f71c7aba4b3e4d13f36482084
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.10.12
|
Security for ai-pr-insight 1.2.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.