{"id":23120530,"url":"https://github.com/tupizz/pr-code-analyzer","last_synced_at":"2025-10-14T09:32:17.670Z","repository":{"id":260176997,"uuid":"880535118","full_name":"tupizz/pr-code-analyzer","owner":"tupizz","description":"🤖 AI-powered code review CLI tool that leverages LLM to analyze pull requests, generate detailed reviews, and create PR descriptions. Supports multiple review modes, git diff analysis, and markdown-formatted outputs.","archived":false,"fork":false,"pushed_at":"2024-11-07T13:55:54.000Z","size":104,"stargazers_count":4,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-10-06T03:45:06.633Z","etag":null,"topics":["ai","automation","code-review","llm","nodejs","openai","pull-request"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/tupizz.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2024-10-29T22:34:13.000Z","updated_at":"2025-08-18T06:08:15.000Z","dependencies_parsed_at":"2025-08-17T00:32:22.952Z","dependency_job_id":"d5285473-bb15-41a5-8e33-6de217f25ab9","html_url":"https://github.com/tupizz/pr-code-analyzer","commit_stats":null,"previous_names":["tupizz/pr-code-analyzer"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/tupizz/pr-code-analyzer","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tupizz%2Fpr-code-analyzer","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tupizz%2Fpr-code-analyzer/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tupizz%2Fpr-code-analyzer/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tupizz%2Fpr-code-analyzer/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/tupizz","download_url":"https://codeload.github.com/tupizz/pr-code-analyzer/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tupizz%2Fpr-code-analyzer/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":279018630,"owners_count":26086404,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-10-14T02:00:06.444Z","response_time":60,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["ai","automation","code-review","llm","nodejs","openai","pull-request"],"created_at":"2024-12-17T06:11:30.109Z","updated_at":"2025-10-14T09:32:17.653Z","avatar_url":"https://github.com/tupizz.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# PR Review Tool\n\n![npm version](https://img.shields.io/npm/v/pr-reviewer)\n![License](https://img.shields.io/github/license/tupizz/pr-code-analyzer)\n\nA CLI tool for automated code review and PR description generation using LLM (Language Learning Model). This tool analyzes Git diffs, structures the changes, and leverages AI to provide insightful code reviews and PR descriptions.\n\n## Features\n\n- 🔍 Automated code review generation\n- 📝 PR description generation with diagrams and topics\n- 🎯 Multiple review modes (brief, detailed, description)\n- 📊 Structured diff analysis\n- 🚀 Command-line interface with rich options\n- 📋 Comprehensive logging system\n- 🛡️ Robust error handling\n\n## Prerequisites\n\n- Node.js (v14 or higher)\n- npm (v6 or higher)\n- Git installed and configured\n- OpenAI API key\n\n### OpenAI API Key Configuration\n\nSet up your OpenAI API key as an environment variable:\n\n```bash\n# Linux/macOS\nexport OPEN_API_KEY=your_openai_api_key\n\n# Windows (Command Prompt)\nset OPEN_API_KEY=your_openai_api_key\n\n# Windows (PowerShell)\n$env:OPEN_API_KEY=\"your_openai_api_key\"\n```\n\n## Installation\n\n1. Install the required dependencies:\n\n```bash\nnpm install commander winston\n```\n\n2. Install the tool globally:\n\n```bash\nnpm install -g .\n```\n\n## Usage\n\n### Basic Command Structure\n\n```bash\npr-reviewer [options]\n```\n\n### Options\n\n```\nOptions:\n  -V, --version                    output version number\n  -b, --branch \u003cbranch\u003e           branch name to review (required)\n  -m, --mode \u003cmode\u003e               review mode (review/description) (default: \"review\")\n  -t, --target-branch \u003cbranch\u003e    target branch to compare against (default: \"development\")\n  -v, --verbose                   enable verbose logging\n  -o, --output \u003coutput\u003e           output folder (default: \"tmp\")\n  -h, --help                      display help for command\n```\n\n### Examples\n\n```bash\n# Basic review of a feature branch\npr-reviewer -b feature/new-feature\n\n# Generate detailed description comparing against main branch\npr-reviewer -b feature/new-feature -m description -t main\n\n# Review with verbose logging\npr-reviewer -b feature/new-feature -v\n\n# Show help\npr-reviewer --help\n```\n\n## Review Modes\n\n1. **review** (default)\n\n   - Performs a detailed code review\n   - Identifies potential issues\n   - Suggests improvements\n   - Reviews code style and best practices\n\n2. **description**\n\n   - Generates comprehensive PR description\n   - Creates diagrams where applicable\n   - Lists key changes and impacts\n   - Provides technical context\n\n3. **brief**\n   - Quick summary of changes\n   - High-level impact analysis\n   - Key points for reviewers\n\n## Output\n\nThe tool generates several output files:\n\n- `combined.log`: Complete execution log\n- `error.log`: Error-specific logging\n- Temporary diff files (automatically cleaned up)\n- LLM review output (saved to specified location)\n\n## How It Works\n\n1. **Initialization**\n\n   - Parses command-line arguments\n   - Validates input parameters\n   - Sets up logging system\n\n2. **Git Operations**\n\n   - Fetches latest changes\n   - Checks out specified branch\n   - Generates diff against target branch\n\n3. **Diff Processing**\n\n   - Parses Git diff output\n   - Structures changes by file\n   - Identifies additions and removals\n\n4. **LLM Integration**\n\n   - Sends structured changes to LLM\n   - Processes LLM response\n   - Generates formatted output\n\n5. **Cleanup**\n   - Removes temporary files\n   - Logs operation completion\n   - Handles any errors\n\n## Error Handling\n\nThe tool includes comprehensive error handling for:\n\n- Git operation failures\n- File system issues\n- LLM communication problems\n- Invalid input parameters\n\nErrors are:\n\n- Logged to error.log\n- Displayed in console with context\n- Handled gracefully with proper cleanup\n\n## Development\n\n### Project Structure\n\n```\npr-reviewer/\n├── src/\n│   ├── GitOperations.js\n│   ├── DiffParser.js\n│   ├── PRReviewer.js\n│   ├── LLMAdapter.js\n│   └── send_to_llm.js\n├── logs/\n│   ├── combined.log\n│   └── error.log\n└── package.json\n```\n\n### Adding New Features\n\n1. Follow the existing class structure\n2. Implement error handling\n3. Add appropriate logging\n4. Update tests if applicable\n\n## Troubleshooting\n\nCommon issues and solutions:\n\n1. **Git access errors**\n\n   - Ensure Git is properly configured\n   - Check repository permissions\n\n2. **API key issues**\n\n   - Verify OPEN_API_KEY is set\n   - Check key validity\n\n3. **Parsing errors**\n   - Ensure branch exists\n   - Check for valid diff output\n\n## Customizing Prompts\n\nThe tool uses customizable prompts for different review modes. These prompts can be modified by editing the `MODE_FOR_PROMPT.js` file in the project root.\n\n### Prompt Structure\n\n```js\n// prompts.js\nmodule.exports = {\n  PROMPTS: {\n    review: `[Your custom review prompt]`,\n    brief: `[Your custom brief prompt]`,\n    description: `[Your custom description prompt]`,\n  },\n};\n```\n\n### Available Modes\n\n1. **review**: Used for detailed code reviews\n2. **brief**: Used for quick summaries\n3. **description**: Used for PR descriptions\n\n### Customizing Prompts\n\nTo modify the prompts:\n\n1. Locate `MODE_FOR_PROMPT.js` in the project root\n2. Edit the desired prompt in the `PROMPTS` object\n3. Save the file - changes will take effect immediately\n\n### Example Customization\n\n```js\n// prompts.js\nmodule.exports = {\n  PROMPTS: {\n    review: `\n      As a senior developer, review this code focusing on:\n      - Performance implications\n      - Security concerns\n      - Best practices\n      - Potential edge cases\n      Please be constructive and specific.\n    `,\n    brief: `\n      Provide a 2-3 sentence summary of the changes.\n      Include:\n      - Main purpose 🎯\n      - Key technical changes 🔧\n      - Impact on users 👥\n    `,\n    description: `\n      Create a comprehensive PR description with:\n      1. Overview of changes\n      2. Technical implementation details\n      3. Testing considerations\n      4. Visual diagrams where applicable\n    `,\n  },\n};\n```\n\n### Best Practices for Custom Prompts\n\n1. **Be Specific**: Clearly define what you want the LLM to focus on\n2. **Format Consistently**: Use clear formatting for better readability\n3. **Include Guidelines**: Add specific instructions for output format\n4. **Keep it Focused**: Each prompt should have a single clear purpose\n5. **Test Changes**: Verify new prompts generate desired outputs\n\n### Adding New Modes\n\nTo add a new review mode:\n\n1. Add your new prompt to the `PROMPTS` object:\n\n   ```js\n   module.exports = {\n     PROMPTS: {\n       // Existing prompts...\n       newMode: `Your new prompt here`,\n     },\n   };\n   ```\n\n2. Use the new mode:\n   ```bash\n   pr-reviewer -b feature/branch -m newMode\n   ```\n\n## License\n\nMIT License - see LICENSE.md for details\n\n## Support\n\nFor bugs and feature requests, please create an issue in the repository.\n\n---\n\n**Note**: This tool is in active development. Please report any issues or suggestions for improvement.\n\n### Pushing to NPM\n\n```bash\n# Increment version\nnpm version patch|minor|major\n\n# Publish\nnpm publish\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftupizz%2Fpr-code-analyzer","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftupizz%2Fpr-code-analyzer","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftupizz%2Fpr-code-analyzer/lists"}