|
| 1 | +# OpenRouter PR Review Action |
| 2 | + |
| 3 | +This GitHub Action integrates with OpenRouter to review pull request diffs, suggest improvements, and scan for vulnerabilities using AI models of your choice. |
| 4 | + |
| 5 | +## Features |
| 6 | + |
| 7 | +- Automated PR code review using AI |
| 8 | +- Customizable AI models through OpenRouter |
| 9 | +- Vulnerability and bug detection |
| 10 | +- Code improvement suggestions |
| 11 | +- Custom prompts for specialized analysis |
| 12 | +- Performance and security insights |
| 13 | + |
| 14 | +## Inputs |
| 15 | + |
| 16 | +| Input | Description | Required | Default | |
| 17 | +| ----------------- | ------------------------------------------ | -------- | -------------------------- | |
| 18 | +| `github_token` | GitHub token for API access | Yes | `${{ github.token }}` | |
| 19 | +| `open_router_key` | Your OpenRouter API key | Yes | - | |
| 20 | +| `model_id` | Model ID to use (e.g., anthropic/claude-2) | Yes | anthropic/claude-2 | |
| 21 | +| `custom_prompt` | Custom prompt for specialized analysis | No | Default code review prompt | |
| 22 | +| `max_tokens` | Maximum tokens in response | No | 2048 | |
| 23 | + |
| 24 | +## Usage |
| 25 | + |
| 26 | +1. Create a new workflow file (e.g., `.github/workflows/pr-review.yml`): |
| 27 | + |
| 28 | +```yaml |
| 29 | +name: PR Review |
| 30 | + |
| 31 | +on: |
| 32 | + pull_request: |
| 33 | + types: [opened, synchronize] |
| 34 | + |
| 35 | +jobs: |
| 36 | + review: |
| 37 | + runs-on: ubuntu-latest |
| 38 | + steps: |
| 39 | + - name: Checkout code |
| 40 | + uses: actions/checkout@v2 |
| 41 | + |
| 42 | + - name: OpenRouter PR Review |
| 43 | + uses: your-username/openrouter-pr-review@v1 |
| 44 | + with: |
| 45 | + github_token: ${{ secrets.GITHUB_TOKEN }} |
| 46 | + open_router_key: ${{ secrets.OPEN_ROUTER_KEY }} |
| 47 | + model_id: 'anthropic/claude-2' |
| 48 | +``` |
| 49 | +
|
| 50 | +### Custom Prompt Example |
| 51 | +
|
| 52 | +You can customize the analysis by providing your own prompt: |
| 53 | +
|
| 54 | +```yaml |
| 55 | +- name: OpenRouter PR Review |
| 56 | + uses: your-username/openrouter-pr-review@v1 |
| 57 | + with: |
| 58 | + github_token: ${{ secrets.GITHUB_TOKEN }} |
| 59 | + open_router_key: ${{ secrets.OPEN_ROUTER_KEY }} |
| 60 | + model_id: 'openai/gpt-4' |
| 61 | + custom_prompt: | |
| 62 | + You are a security-focused code reviewer. Please analyze this code diff with emphasis on: |
| 63 | + 1. Security vulnerabilities |
| 64 | + 2. Authentication/authorization issues |
| 65 | + 3. Data validation |
| 66 | + 4. Input sanitization |
| 67 | + 5. Secure coding practices |
| 68 | +``` |
| 69 | +
|
| 70 | +## Publishing and Testing Guide |
| 71 | +
|
| 72 | +### Local Testing |
| 73 | +
|
| 74 | +1. Clone this repository |
| 75 | +2. Create a new branch for testing: |
| 76 | + ```bash |
| 77 | + git checkout -b test-action |
| 78 | + ``` |
| 79 | +3. Make some changes to test |
| 80 | +4. Create a pull request |
| 81 | +5. Add your OpenRouter API key to repository secrets as `OPEN_ROUTER_KEY` |
| 82 | +6. The action will automatically run on your PR |
| 83 | + |
| 84 | +### Publishing to GitHub Marketplace |
| 85 | + |
| 86 | +1. Push your code to GitHub: |
| 87 | + |
| 88 | + ```bash |
| 89 | + git add . |
| 90 | + git commit -m "Initial release" |
| 91 | + git push origin main |
| 92 | + ``` |
| 93 | + |
| 94 | +2. Create a new release: |
| 95 | + |
| 96 | + - Go to your repository on GitHub |
| 97 | + - Click "Releases" |
| 98 | + - Click "Create a new release" |
| 99 | + - Choose a tag (e.g., "v1.0.0") |
| 100 | + - Title the release (e.g., "Initial Release") |
| 101 | + - Publish the release |
| 102 | + |
| 103 | +3. Update in Other Repositories: |
| 104 | + ```yaml |
| 105 | + - uses: your-username/openrouter-pr-review@v1 |
| 106 | + ``` |
| 107 | + Replace `your-username` with your GitHub username |
| 108 | + |
| 109 | +### Testing in Other Repositories |
| 110 | + |
| 111 | +1. Add the action to your repository's workflow: |
| 112 | + |
| 113 | + ```yaml |
| 114 | + name: PR Review |
| 115 | + on: |
| 116 | + pull_request: |
| 117 | + types: [opened, synchronize] |
| 118 | +
|
| 119 | + jobs: |
| 120 | + review: |
| 121 | + runs-on: ubuntu-latest |
| 122 | + steps: |
| 123 | + - uses: actions/checkout@v3 |
| 124 | + - uses: your-username/openrouter-pr-review@v1 |
| 125 | + with: |
| 126 | + github_token: ${{ secrets.GITHUB_TOKEN }} |
| 127 | + open_router_key: ${{ secrets.OPEN_ROUTER_KEY }} |
| 128 | + model_id: 'anthropic/claude-2' |
| 129 | + ``` |
| 130 | + |
| 131 | +2. Add your OpenRouter API key: |
| 132 | + |
| 133 | + - Go to repository Settings |
| 134 | + - Select Secrets and variables → Actions |
| 135 | + - Create a new secret named `OPEN_ROUTER_KEY` |
| 136 | + - Add your OpenRouter API key as the value |
| 137 | + |
| 138 | +3. Create a test PR to verify the action works |
| 139 | + |
| 140 | +## Models |
| 141 | + |
| 142 | +Some recommended models: |
| 143 | + |
| 144 | +- `anthropic/claude-2`: Excellent for detailed code analysis |
| 145 | +- `openai/gpt-4`: Strong general-purpose code review |
| 146 | +- `anthropic/claude-instant-v1`: Faster, more economical option |
| 147 | + |
| 148 | +## License |
| 149 | + |
| 150 | +This project is licensed under the MIT License. |
0 commit comments