# 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 `repo` scope)
- An OpenAI API key
### Install via pip
```bash
pip3 install ai-pr-insight
```
### Manual Installation
```bash
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:
```bash
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:
```bash
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:
```bash
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 between `economy` (GPT-3.5) and `premium` (GPT-4).
### Summarize PR Analysis Results
To consolidate and summarize analysis results:
```bash
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:
```bash
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:
```ini
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:
```bash
python3 -m unittest discover tests
```
---
## Example Outputs
### Example PR Comments Output (`pr-comments.json`)
```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`)
```markdown
# 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](LICENSE) for details.
## Contributing
Contributions are welcome! Please read our [Contributing Guidelines](CONTRIBUTING.md) 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**
Raw data
{
"_id": null,
"home_page": "https://github.com/kadivar/ai-pr-insight",
"name": "ai-pr-insight",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.8",
"maintainer_email": null,
"keywords": "github, pull-requests, code-review, ai, openai",
"author": "Mohammadreza Kadivar",
"author_email": "me.kadivar@gmail.com",
"download_url": "https://files.pythonhosted.org/packages/41/ac/67aaa688caaa9037ec04c2ec2e32bd9e9ce358104cb8d7f37b894632381b/ai_pr_insight-1.1.0.tar.gz",
"platform": null,
"description": "# AI PR Insight\n\nAI 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.\n\n## Features\n\n- **Fetch PR Comments**: Extract PR comments from GitHub repositories you have access to.\n- **AI-Powered Analysis**: Use OpenAI's GPT models to analyze comments and generate actionable insights.\n- **Checklist Generation**: Create a checklist of best practices and common issues from PR comments.\n- **Customizable Filters**: Filter comments by year, month, organization, or repository.\n- **Standalone CLI**: Easy-to-use command-line interface for seamless integration into your workflow.\n- **Summarization**: Consolidate and summarize PR analysis results for better insights.\n- **Verbose Logging**: Debug mode available for detailed logs during execution.\n\n---\n\n## Installation\n\n### Prerequisites\n\nEnsure you have the following before installation:\n\n- Python 3.8 or higher\n- A GitHub personal access token (with `repo` scope)\n- An OpenAI API key\n\n### Install via pip\n\n```bash\npip3 install ai-pr-insight\n```\n\n### Manual Installation\n\n```bash\ngit clone https://github.com/kadivar/ai-pr-insight.git\ncd ai-pr-insight\npip3 install -r requirements.txt\n```\n\n---\n\n## Usage\n\nAI PR Insight provides three main commands: `fetch`, `analyze`, and `summarize`.\n\n### Fetch PR Comments\n\nTo fetch PR comments from a specific year and month within an organization:\n\n```bash\nai-pr-insight fetch --year 2024 --month 2 --org my-org --output_file pr-comments.json\n```\n\nYou can also filter by a specific GitHub username:\n\n```bash\nai-pr-insight fetch --year 2024 --month 2 --username my-user --output_file pr-comments.json\n```\n\n### Analyze PR Comments\n\nTo analyze PR comments and generate a checklist:\n\n```bash\nai-pr-insight analyze --input_file pr-comments.json --output_dir output --batch-size 20 --model-tier premium\n```\n\n- `batch-size`: Number of comments to process in each batch.\n- `model-tier`: Choose between `economy` (GPT-3.5) and `premium` (GPT-4).\n\n### Summarize PR Analysis Results\n\nTo consolidate and summarize analysis results:\n\n```bash\nai-pr-insight summarize --input_dir analysis_results --output_dir summary_results --similarity-threshold 0.9 --abstraction-threshold 0.85\n```\n\n- `similarity-threshold`: Defines similarity grouping (range: 0.0 - 1.0).\n- `abstraction-threshold`: Defines abstraction grouping (range: 0.0 - 1.0).\n\n### Enable Debug Mode\n\nFor detailed logs, add the `--verbose` flag:\n\n```bash\nai-pr-insight fetch --year 2024 --month 2 --org my-org --output_file pr-comments.json --verbose\n```\n\n---\n\n## Configuration\n\nAI PR Insight uses a `.env` file for configuration. Place this file in the root directory with the following variables:\n\n```ini\nGITHUB_TOKEN=your_github_personal_access_token\nOPENAI_API_KEY=your_openai_api_key\nCACHE_EXPIRATION_MINUTES=120\nDEBUG=false\nSOURCE_CODE_LINES_OFFSET=3\n```\n\n### Environment Variables Explained\n\n- `GITHUB_TOKEN`: Your GitHub personal access token (required).\n- `OPENAI_API_KEY`: Your OpenAI API key (required).\n- `CACHE_EXPIRATION_MINUTES`: Cache expiration time in minutes (default: 120).\n- `DEBUG`: Enable debug mode (default: false).\n- `SOURCE_CODE_LINES_OFFSET`: Number of lines to include around a code snippet (default: 3).\n\n---\n\n## Running Tests\n\nRun them using:\n\n```bash\npython3 -m unittest discover tests\n```\n\n---\n\n## Example Outputs\n\n### Example PR Comments Output (`pr-comments.json`)\n\n```json\n[\n {\n \"author\": \"johndoe\",\n \"repository\": \"surveyanyplace/survey-ui\",\n \"pr_number\": 1234,\n \"pr_title\": \"Refactor UserProfile component to use hooks [SA-12345]\",\n \"pr_url\": \"https://github.com/surveyanyplace/survey-ui/pull/1234\",\n \"datetime\": \"2025-03-15T14:45:22Z\",\n \"message\": \"A: I think we should also consider adding error handling for the API call in this component.\",\n \"comment_url\": \"https://github.com/surveyanyplace/survey-ui/pull/1234#discussion_r1987654321\",\n \"permalink\": \"https://github.com/surveyanyplace/survey-ui/pull/1234#discussion_r1987654321\",\n \"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;\"\n }\n]\n```\n\n### Example Checklist Output (`checklist.md`)\n\n```markdown\n# PR Review Checklist\n\n- [ ] Refactor complex functions for better readability.\n- [ ] Improve documentation for unclear code sections.\n- [ ] Ensure tests cover newly introduced changes.\n```\n\n---\n\n## License\n\nAI PR Insight is licensed under the GNU Affero General Public License (AGPL). See [LICENSE](LICENSE) for details.\n\n## Contributing\n\nContributions are welcome! Please read our [Contributing Guidelines](CONTRIBUTING.md) for details on how to get started.\n\n## Support\n\nIf you encounter any issues or have questions, please open an issue on the GitHub repository.\n\n**Made with \u2764\ufe0f by Mohammadreza Kadivar**\n",
"bugtrack_url": null,
"license": "GNU AGPL",
"summary": "A tool to analyze GitHub PR comments and generate actionable insights using AI.",
"version": "1.1.0",
"project_urls": {
"Bug Reports": "https://github.com/kadivar/ai-pr-insight/issues",
"Homepage": "https://github.com/kadivar/ai-pr-insight",
"Source": "https://github.com/kadivar/ai-pr-insight"
},
"split_keywords": [
"github",
" pull-requests",
" code-review",
" ai",
" openai"
],
"urls": [
{
"comment_text": null,
"digests": {
"blake2b_256": "ab286a53b64f7c6902219fe7cafb5c5c047716c9bedc7ad39a40c523c1c9eb4b",
"md5": "50337a2317eca4b6be62422c131b5198",
"sha256": "a44981c94c3f6b98a3524c8ca5f6c29f5f033464371098308cd6c735b9797a0a"
},
"downloads": -1,
"filename": "ai_pr_insight-1.1.0-py3-none-any.whl",
"has_sig": false,
"md5_digest": "50337a2317eca4b6be62422c131b5198",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.8",
"size": 24184,
"upload_time": "2025-02-28T00:30:10",
"upload_time_iso_8601": "2025-02-28T00:30:10.234873Z",
"url": "https://files.pythonhosted.org/packages/ab/28/6a53b64f7c6902219fe7cafb5c5c047716c9bedc7ad39a40c523c1c9eb4b/ai_pr_insight-1.1.0-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": null,
"digests": {
"blake2b_256": "41ac67aaa688caaa9037ec04c2ec2e32bd9e9ce358104cb8d7f37b894632381b",
"md5": "0d45bd79de72b5e74479bf936884a89b",
"sha256": "6d27c3fc4a74fb1e6ab0a64ff3d8da9e752e77254c5efca668462781a73b3637"
},
"downloads": -1,
"filename": "ai_pr_insight-1.1.0.tar.gz",
"has_sig": false,
"md5_digest": "0d45bd79de72b5e74479bf936884a89b",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.8",
"size": 26963,
"upload_time": "2025-02-28T00:30:12",
"upload_time_iso_8601": "2025-02-28T00:30:12.232452Z",
"url": "https://files.pythonhosted.org/packages/41/ac/67aaa688caaa9037ec04c2ec2e32bd9e9ce358104cb8d7f37b894632381b/ai_pr_insight-1.1.0.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2025-02-28 00:30:12",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "kadivar",
"github_project": "ai-pr-insight",
"travis_ci": false,
"coveralls": false,
"github_actions": false,
"requirements": [
{
"name": "requests",
"specs": [
[
">=",
"2.30.0"
]
]
},
{
"name": "python-dotenv",
"specs": [
[
">=",
"1.0.0"
]
]
},
{
"name": "openai",
"specs": [
[
">=",
"1.3.0"
]
]
},
{
"name": "tqdm",
"specs": [
[
">=",
"4.65.0"
]
]
},
{
"name": "numpy",
"specs": [
[
">=",
"1.24.0"
]
]
},
{
"name": "scikit-learn",
"specs": [
[
">=",
"1.2.0"
]
]
},
{
"name": "python-dateutil",
"specs": [
[
">=",
"2.8.0"
]
]
},
{
"name": "tiktoken",
"specs": [
[
">=",
"0.5.0"
]
]
}
],
"lcname": "ai-pr-insight"
}