An automated GitHub Pull Request review tool that performs comprehensive first-pass code reviews. This tool helps identify common issues before human review, saving time and ensuring consistent code quality checks.
The PR Review Assistant checks for:
- β Unit Test Coverage - Verifies if unit tests are present for code changes
- π« Jira Integration - Checks if PR is linked to a Jira issue
- π Security Vulnerabilities - Scans for common security issues (hardcoded credentials, SQL injection, XSS, etc.)
- π Code Bugs - Detects common coding mistakes and anti-patterns
- β‘ Performance Issues - Identifies inefficient code patterns (nested loops, N+1 queries, etc.)
- π Code Quality - Checks for syntax issues, code smells, and complexity
- Node.js 16+ installed
- GitHub Personal Access Token with
repoandread:orgscopes
- Clone or download this project:
cd pr-review-assistant- Install dependencies:
npm install- Create a
.envfile from the example:
cp .env.example .env- Add your GitHub token to
.env:
GITHUB_TOKEN=your_github_personal_access_tokenTo create a GitHub token:
- Go to https://github.com/settings/tokens
- Click "Generate new token (classic)"
- Select scopes:
repo,read:org - Copy the token and paste it in your
.envfile
- (Optional) Configure Jira settings in
.env:
JIRA_BASE_URL=https://your-company.atlassian.net
JIRA_PROJECT_KEY=PROJRun the tool and follow the prompts:
npm startOr:
node src/index.jsYou'll be prompted to:
- Enter the GitHub PR URL (e.g.,
https://github.com/owner/repo/pull/123) - Wait for the analysis to complete
- Review the comprehensive report
- Optionally save the report as JSON
$ npm start
π€ PR Review Assistant
β GitHub client initialized
? Enter GitHub PR URL: https://github.com/facebook/react/pull/12345
β PR: facebook/react#12345
β PR details fetched
β Found 15 changed file(s)
β Unit test analysis complete
β Jira check complete
β Security scan complete
β Code quality analysis complete
β Performance analysis complete
================================================================================
π PULL REQUEST REVIEW REPORT
================================================================================
π Pull Request Information:
Title: Fix memory leak in useEffect
Author: johndoe
Branch: fix/memory-leak
Files Changed: 15
Additions: +234 | Deletions: -89
URL: https://github.com/facebook/react/pull/12345
π§ͺ UNIT TESTS
--------------------------------------------------------------------------------
β
Found Jira issue(s): REACT-456
π‘ Recommendations:
β’ Add unit tests for the new/modified code
β’ Consider test-driven development (TDD) approach
...The tool checks the following:
- β
Presence of test files (
.test.js,.spec.js, etc.) - β Test-to-source file ratio
- β Test file locations and naming conventions
- β Jira issue reference in PR title
- β Jira issue reference in PR description
- β Jira issue reference in branch name
- β Valid Jira issue format (e.g., PROJ-123)
- π Hardcoded credentials (passwords, API keys, tokens)
- π SQL injection vulnerabilities
- π XSS vulnerabilities (innerHTML, eval, etc.)
- π Weak cryptography (MD5, SHA1)
- π Command injection risks
- π Insecure configurations (disabled SSL verification)
- π Path traversal vulnerabilities
- π Sensitive data exposure in logs
- π Loose equality operators (== vs ===)
- π Use of
varinstead oflet/const - π Empty catch blocks
- π Console statements in production code
- π Debugger statements
- π TODO/FIXME comments
- π Bare except clauses (Python)
- π Wildcard imports
- β‘ Nested loops (O(nΒ²) or worse complexity)
- β‘ Array operations in loops (indexOf, includes, find)
- β‘ String concatenation in loops
- β‘ Synchronous file operations
- β‘ Database queries in loops (N+1 problem)
- β‘ Memory leaks (uncleaned intervals/listeners)
- β‘ High cyclomatic complexity
- β‘ RegExp creation in loops
The tool generates a comprehensive report with:
- PR Information: Title, author, branch, file changes
- Detailed Findings: Categorized by severity (HIGH, MEDIUM, LOW)
- File and Line References: Exact locations of issues
- Recommendations: Actionable suggestions for improvement
- Overall Summary: Pass/fail status and checklist
- Final Recommendation: Merge decision guidance
- π΄ HIGH: Critical issues that must be fixed before merge
- π‘ MEDIUM: Important issues that should be addressed
- π΅ LOW: Minor issues or suggestions for improvement
Reports can be saved as JSON files for:
- Documentation and audit trails
- Integration with CI/CD pipelines
- Historical analysis and metrics
- Sharing with team members
Example JSON structure:
{
"timestamp": "2024-01-15T10:30:00.000Z",
"prInfo": { ... },
"unitTests": { ... },
"jira": { ... },
"security": { ... },
"codeQuality": { ... },
"performance": { ... }
}Create a .env file with the following variables:
# Required
GITHUB_TOKEN=your_github_token
# Optional - Jira Integration
JIRA_BASE_URL=https://your-company.atlassian.net
JIRA_PROJECT_KEY=PROJ
# Optional - Feature Toggles
ENABLE_SECURITY_SCAN=true
ENABLE_PERFORMANCE_CHECK=true
ENABLE_JIRA_CHECK=trueThe tool is modular and can be extended with additional analyzers:
- Create a new analyzer in
src/analyzers/ - Implement the
analyze()method - Import and use in
src/index.js
Example analyzer structure:
export class CustomAnalyzer {
analyze(files, githubClient, owner, repo, ref) {
// Your analysis logic
return {
issues: [],
recommendations: []
};
}
}The tool currently supports analysis for:
- JavaScript/TypeScript (.js, .ts, .jsx, .tsx)
- Python (.py)
- Java (.java)
- C# (.cs)
- Ruby (.rb)
- Go (.go)
- PHP (.php)
- C/C++ (.c, .cpp, .h)
- Swift (.swift)
- Kotlin (.kt)
- Scala (.scala)
- Rust (.rs)
- Static Analysis Only: Does not execute code or run tests
- Pattern-Based Detection: May have false positives/negatives
- Rate Limits: Subject to GitHub API rate limits
- File Size: Large files may take longer to analyze
- Language Support: Some patterns are language-specific
- Run Locally First: Test PRs before pushing
- Combine with CI/CD: Integrate into your pipeline
- Human Review: Use as a first pass, not a replacement for human review
- Keep Updated: Regularly update dependencies
- Customize Patterns: Adjust patterns for your codebase
- Ensure
.envfile exists in the project root - Verify the token is correctly set in
.env - Check token has required scopes
- Wait for rate limit to reset (usually 1 hour)
- Use authenticated requests (token should help)
- Consider GitHub Enterprise for higher limits
- Verify PR URL is correct
- Check token has access to the repository
- Ensure repository is not private (or token has access)
MIT License - feel free to use and modify for your needs.
Contributions are welcome! Please:
- Fork the repository
- Create a feature branch
- Add tests for new features
- Submit a pull request
For issues or questions:
- Open an issue on GitHub
- Check existing issues for solutions
- Review the troubleshooting section
Happy Reviewing! π