Claude 183d49dd6a Improve code resilience, error handling, and logging
Major improvements:
- Add comprehensive logging with @actions/core (info, warning, error, debug)
- Implement retry logic with exponential backoff for all network operations
- Add timeout handling for API calls (2 minute default)
- Improve error handling with specific messages and context
- Add input validation for API keys and PR numbers
- Implement rate limit handling (429 responses)
- Add diff size limits to prevent API token overflow
- Fix flawed markdown escape logic in review posting
- Add progress indicators with core.startGroup/endGroup
- Mask sensitive data (API keys) in logs
- Add unhandled rejection and exception handlers
- Improve git operation error handling and output capture
- Add JSDoc comments for all functions
- Fix npm security vulnerabilities

The action is now much more resilient to:
- Network failures and transient errors
- API rate limiting
- Large diffs
- Timeout issues
- Invalid inputs

Logging improvements provide better visibility into:
- Operation progress and timing
- Retry attempts
- Error context and debugging information
- Resource usage (diff size, review length)
2025-11-14 14:30:56 +00:00
2025-02-10 17:23:06 -05:00
2024-12-10 18:30:01 -05:00
2024-12-10 18:42:08 -05:00
fix
2024-12-10 18:57:57 -05:00
2024-12-10 18:42:08 -05:00
2024-12-10 18:42:08 -05:00
2024-12-10 18:30:01 -05:00
2024-12-10 18:47:28 -05:00
2025-02-10 16:06:09 -05:00

Claude Code Review Action

A GitHub Action that performs automated code reviews using Claude Sonnet 3.5, an AI assistant from Anthropic.

Features

  • Analyzes code changes in pull requests
  • Provides detailed feedback on code quality
  • Identifies potential issues and suggests improvements
  • Checks for security issues and best practices

Usage

Add this to your GitHub workflow file (e.g. .github/workflows/review.yml):

name: Claude Code Review

permissions:
  contents: read
  pull-requests: write

on:
  # Run on new/updated PRs
  pull_request:
    types: [opened, reopened, synchronize]
  
  # Allow manual triggers for existing PRs
  workflow_dispatch:
    inputs:
      pr_number:
        description: 'Pull Request Number'
        required: true
        type: string

jobs:
  code-review:
    runs-on: ubuntu-latest
    environment: development_environment
    steps:
      - uses: actions/checkout@v4
        with:
          fetch-depth: 0
          
      - name: Run Claude Review
        uses: pacnpal/claude-code-review@main
        with:
          github-token: ${{ secrets.GITHUB_TOKEN }}
          anthropic-key: ${{ secrets.ANTHROPIC_API_KEY }}
          pr-number: ${{ github.event.pull_request.number || inputs.pr_number }}
  • Click on "Claude Code Review" Action under Actions tab.
  • Click "Run Workflow"
  • Fill in branch and pull request ID and click "Run Workflow"

Setup

  1. Create repository secret ANTHROPIC_API_KEY with your Claude API key from Anthropic
  2. The GITHUB_TOKEN is automatically provided by GitHub Actions

Inputs

Input Description Required Default
github-token GitHub token for API access Yes N/A
anthropic-key Anthropic API key for Claude Yes N/A
pr-number Pull request number to review Yes N/A

Outputs

Output Description
diff_size Size of the relevant code changes
review Generated code review content

Review Format

The action provides detailed code reviews covering:

  1. Potential conflicts with existing codebase
  2. Code correctness and potential bugs
  3. Security vulnerabilities and risks
  4. Performance implications
  5. Maintainability and readability issues
  6. Adherence to best practices
  7. Suggestions for improvements

Each issue found includes:

  • Clear problem explanation
  • Severity rating (Critical/High/Medium/Low)
  • Specific recommendations
  • Code examples where helpful

Example Review

# Claude Code Review

1. **Potential conflicts with existing codebase**:
   - No apparent conflicts identified
   
2. **Code correctness and potential bugs**:
   - **Medium Severity**: Potential null pointer in user handling
   - Recommendation: Add null check before accessing user object
   
3. **Security vulnerabilities and risks**: 
   - **High Severity**: SQL injection vulnerability in query construction
   - Recommendation: Use parameterized queries

Development

  1. Clone the repository
  2. Install dependencies:
npm install
  1. Make changes to action.js

  2. Build the action:

npm run build
  1. Run tests:
npm test

Contributing

Contributions are welcome! Please:

  1. Fork the repository
  2. Create a feature branch
  3. Make your changes
  4. Run tests
  5. Submit a pull request

License

MIT License - see the LICENSE file for details

Support

  • Open an issue for bugs/feature requests
  • Submit a PR to contribute
  • Contact maintainers for other questions
Description
GitHub Action for code review using Claude
Readme MIT 2.9 MiB
Languages
JavaScript 100%