An AI-powered GitHub Action that automatically analyzes pull requests using Claude AI and provides intelligent code review insights, risk assessments, and complexity ratings.
π₯ Watch the setup tutorial on YouTube
PR Agent analyzes your pull requests and provides:
- Summary: Clear description of what the change does and its purpose
- Potential Risks: Identification of possible bugs, edge cases, or issues
- Complexity Rating: A 1-5 scale rating of the PR's complexity
- Actionable Insights: Specific recommendations for reviewers
Before setting up PR Agent in your project, you'll need:
- Anthropic API Key: Sign up at Anthropic Console to get your API key
- GitHub Repository: With permissions to add workflows and secrets
-
Create a workflow file in your repository:
mkdir -p .github/workflows
-
Create
.github/workflows/pr-agent.yml:name: PR Analyzer on: pull_request: types: [opened, synchronize, reopened] permissions: pull-requests: write issues: write contents: read jobs: analyze: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - name: Run PR Analyzer uses: techdebtgpt/[email protected] with: config-path: .pr-analyzer.yml env: ANTHROPIC_API_KEY: ${{ secrets.ANTHROPIC_API_KEY }} GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
Add your Anthropic API key to your repository secrets:
- Go to your repository on GitHub
- Navigate to Settings β Secrets and variables β Actions
- Click New repository secret
- Name:
ANTHROPIC_API_KEY - Value: Your Anthropic API key
- Click Add secret
Note:
GITHUB_TOKENis automatically provided by GitHub Actions, no manual setup required.
Once set up, PR Agent automatically runs on:
- New pull requests (
opened) - Updates to existing pull requests (
synchronize) - Reopened pull requests (
reopened)
- PR Opened/Updated: When a PR is created or updated, the workflow triggers
- Fetch Changes: The action retrieves all file changes (diffs) from the PR
- AI Analysis: Sends the diff to Claude AI for analysis
- Post Comment: Posts a comprehensive analysis comment on the PR
When PR Agent analyzes your pull request, it posts a comment like:
## π€ AI Analysis
### Summary
This PR refactors the authentication middleware to use JWT tokens instead of session-based auth. It introduces a new TokenService class and updates all route handlers to use the new authentication method.
### Potential Risks
- The migration from session to JWT may break existing authenticated users
- No token expiration handling is implemented in the TokenService
- Error handling in the authenticate middleware could expose sensitive information
### Complexity: 4/5
This is a significant architectural change affecting multiple parts of the application. Careful testing of all authenticated endpoints is recommended.
### Recommendations
- Add integration tests for the new authentication flow
- Implement token refresh mechanism
- Review error messages to ensure no sensitive data leaksIf you want to contribute or modify PR Agent:
git clone https://github.com/YOUR_USERNAME/pr-agent.git
cd pr-agentnpm installnpm run build:actionCreates the dist/ directory that is neccessary for the build to run
To test the action locally, you can:
-
Set environment variables:
ANTHROPIC_API_KEY="your-api-key" -
Create a test PR in a repository you own
-
Run the action (requires GitHub Actions context)
pr-agent/
βββ src/
β βββ action.ts # Main GitHub Action entry point
β βββ analyzer.ts # Claude AI integration
β βββ types.ts # TypeScript type definitions
β βββ index.ts # Additional exports
βββ dist/ # Compiled JavaScript (generated)
βββ action.yml # GitHub Action configuration
βββ .pr-analyzer.yml # PR Analyzer file configuration
βββ package.json # Node.js dependencies
βββ tsconfig.json # TypeScript configuration
βββ README.md # This file
- Trigger: GitHub Action triggers on PR events
- Fetch Diffs: Uses GitHub API to retrieve all changed files and their diffs
- Prepare Prompt: Constructs a detailed prompt with the PR title and diffs
- AI Analysis: Sends to Claude 3.5 Sonnet for analysis
- Parse Response: Extracts structured insights from Claude's response
- Post Comment: Creates a formatted comment on the PR using GitHub API
- Verify workflow file is in
.github/workflows/directory - Check workflow triggers match PR events
- Ensure repository permissions allow Actions to run
- Verify
ANTHROPIC_API_KEYsecret is set correctly - Check workflow permissions include
pull-requests: write - Review Action logs for error messages
- Check if your Anthropic API key is valid and has available credits
- Verify the API key has not expired
- Review Action logs for detailed error messages
- For very large PRs, the diff might exceed token limits
- Consider breaking large PRs into smaller, focused changes
- Future versions will include diff size limits and chunking
Contributions are welcome! Please:
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests if applicable
- Submit a pull request
For issues, questions, or feature requests:
- Open an issue on GitHub Issues
- Check existing issues for solutions
- Review Action logs for debugging
Planned features:
- Configuration file support (
.pr-analyzer.yml) - Customizable analysis prompts
- Support for multiple AI providers
- Diff size limits and smart chunking
- File-level analysis comments
- Security vulnerability detection
- Performance impact analysis
- Custom analysis rules