|
| 1 | +# Patchwork AutoFix Action |
| 2 | + |
| 3 | +This GitHub Action uses [patchwork-cli](https://docs.patched.codes/patchwork/quickstart) to automatically fix code vulnerabilities in your repository using LLMs. |
| 4 | + |
| 5 | +## Features |
| 6 | + |
| 7 | +- Automatically detects vulnerabilities using Semgrep |
| 8 | +- Generates fixes using LLMs (OpenAI, local models, or custom endpoints) |
| 9 | +- Creates pull requests with the fixes |
| 10 | +- Configurable severity and compatibility thresholds |
| 11 | +- Supports custom branch naming and PR behavior |
| 12 | + |
| 13 | +## Usage |
| 14 | + |
| 15 | +```yaml |
| 16 | +name: Security AutoFix |
| 17 | +on: |
| 18 | + schedule: |
| 19 | + - cron: "0 0 * * *" # Run daily |
| 20 | + workflow_dispatch: # Allow manual triggers |
| 21 | + |
| 22 | +jobs: |
| 23 | + autofix: |
| 24 | + runs-on: ubuntu-latest |
| 25 | + steps: |
| 26 | + - uses: actions/checkout@v3 |
| 27 | + - uses: your-username/patchwork-autofix@v1 |
| 28 | + with: |
| 29 | + github_token: ${{ secrets.GITHUB_TOKEN }} |
| 30 | + openai_api_key: ${{ secrets.OPENAI_API_KEY }} |
| 31 | +``` |
| 32 | +
|
| 33 | +## Inputs |
| 34 | +
|
| 35 | +### Required |
| 36 | +
|
| 37 | +One of the following is required: |
| 38 | +
|
| 39 | +- `patched_api_key`: Patched API key for using Patched services ([Get an API key](https://app.patched.codes/api-keys)) |
| 40 | +- `openai_api_key`: OpenAI API key for the LLM ([Get an API key](https://platform.openai.com/account/api-keys)) |
| 41 | + |
| 42 | +### Optional |
| 43 | + |
| 44 | +- `github_token`: GitHub token for creating pull requests (default: [Automatically set by GitHub](https://docs.github.com/en/actions/security-for-github-actions/security-guides/automatic-token-authentication)) |
| 45 | +- `model`: LLM model to use (default: gpt-3.5-turbo) |
| 46 | +- `client_base_url`: Base URL for the LLM API (default: https://api.openai.com/v1) |
| 47 | +- `vulnerability_limit`: Maximum number of vulnerabilities to fix (default: 10, -1 for no limit) |
| 48 | +- `severity`: Minimum severity level (unknown/note/info/warning/low/medium/error/high/critical) |
| 49 | +- `compatibility`: Minimum compatibility threshold (unknown/low/medium/high) |
| 50 | +- `branch_prefix`: Prefix for the created branch |
| 51 | +- `disable_branch`: Disable creating new branches |
| 52 | +- `disable_pr`: Disable creating pull requests |
| 53 | +- `force_pr_creation`: Force push commits to existing PR |
| 54 | + |
| 55 | +## Examples |
| 56 | + |
| 57 | +### Basic Usage |
| 58 | + |
| 59 | +```yaml |
| 60 | +- uses: your-username/patchwork-autofix@v1 |
| 61 | + with: |
| 62 | + github_token: ${{ secrets.GITHUB_TOKEN }} |
| 63 | + openai_api_key: ${{ secrets.OPENAI_API_KEY }} |
| 64 | +``` |
| 65 | + |
| 66 | +### Using Custom Model |
| 67 | + |
| 68 | +```yaml |
| 69 | +- uses: your-username/patchwork-autofix@v1 |
| 70 | + with: |
| 71 | + github_token: ${{ secrets.GITHUB_TOKEN }} |
| 72 | + openai_api_key: ${{ secrets.OPENAI_API_KEY }} |
| 73 | + model: "gpt-4" |
| 74 | + client_base_url: "https://api.openai.com/v1" |
| 75 | +``` |
| 76 | + |
| 77 | +### High Severity Only |
| 78 | + |
| 79 | +```yaml |
| 80 | +- uses: your-username/patchwork-autofix@v1 |
| 81 | + with: |
| 82 | + github_token: ${{ secrets.GITHUB_TOKEN }} |
| 83 | + openai_api_key: ${{ secrets.OPENAI_API_KEY }} |
| 84 | + severity: "high" |
| 85 | + vulnerability_limit: 5 |
| 86 | +``` |
| 87 | + |
| 88 | +## License |
| 89 | + |
| 90 | +MIT |
| 91 | + |
| 92 | +## Contributing |
| 93 | + |
| 94 | +Contributions are welcome! Please feel free to submit a Pull Request. |
0 commit comments