Skip to content

Commit 28a5e03

Browse files
committed
Add base action
0 parents  commit 28a5e03

File tree

2 files changed

+184
-0
lines changed

2 files changed

+184
-0
lines changed

README.md

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
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.

action.yml

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
name: 'Patchwork AutoFix'
2+
description: 'Run Autofix patchflow using patchwork-cli to automatically fix code vulnerabilities'
3+
branding:
4+
icon: 'shield'
5+
color: 'green'
6+
author: '@patched-codes'
7+
8+
inputs:
9+
github_token:
10+
description: 'GitHub token for creating pull requests'
11+
required: false
12+
default: '${{ secrets.GITHUB_TOKEN }}'
13+
openai_api_key:
14+
description: 'OpenAI API key for the LLM'
15+
required: false
16+
patched_api_key:
17+
description: 'Patched API key for using Patched services'
18+
required: false
19+
model:
20+
description: 'LLM model to use (default: gpt-3.5-turbo)'
21+
required: false
22+
default: 'gpt-3.5-turbo'
23+
client_base_url:
24+
description: 'Base URL for the LLM API (default: https://api.openai.com/v1)'
25+
required: false
26+
default: 'https://api.openai.com/v1'
27+
vulnerability_limit:
28+
description: 'Maximum number of vulnerabilities to fix (default: 10, -1 for no limit)'
29+
required: false
30+
default: '10'
31+
severity:
32+
description: 'Minimum severity level of vulnerabilities to fix (unknown/note/info/warning/low/medium/error/high/critical)'
33+
required: false
34+
default: 'medium'
35+
compatibility:
36+
description: 'Minimum compatibility threshold for fixes (unknown/low/medium/high)'
37+
required: false
38+
default: 'medium'
39+
branch_prefix:
40+
description: 'Prefix for the created branch'
41+
required: false
42+
default: 'autofix'
43+
disable_branch:
44+
description: 'Disable creating new branches'
45+
required: false
46+
default: 'false'
47+
disable_pr:
48+
description: 'Disable creating pull requests'
49+
required: false
50+
default: 'false'
51+
force_pr_creation:
52+
description: 'Force push commits to existing PR'
53+
required: false
54+
default: 'false'
55+
56+
outputs:
57+
pr_url:
58+
description: 'URL of the created pull request'
59+
value: '${{ steps.autofix.outputs.pr_url }}'
60+
61+
runs:
62+
using: 'composite'
63+
steps:
64+
- name: Set up Python
65+
uses: actions/setup-python@v4
66+
with:
67+
python-version: '3.x'
68+
69+
- name: Install dependencies
70+
shell: bash
71+
run: |
72+
python -m pip install --upgrade pip
73+
pip install 'patchwork-cli[security]'
74+
75+
- name: Run Autofix
76+
shell: bash
77+
run: |
78+
patchwork AutoFix \
79+
github_api_key=${{ inputs.github_token }} \
80+
${inputs.openai_api_key:+"openai_api_key=${{ inputs.openai_api_key }}"} \
81+
${inputs.patched_api_key:+"patched_api_key=${{ inputs.patched_api_key }}"} \
82+
model=${{ inputs.model }} \
83+
client_base_url=${{ inputs.client_base_url }} \
84+
vulnerability_limit=${{ inputs.vulnerability_limit }} \
85+
severity=${{ inputs.severity }} \
86+
compatibility=${{ inputs.compatibility }} \
87+
branch_prefix=${{ inputs.branch_prefix }} \
88+
disable_branch=${{ inputs.disable_branch }} \
89+
disable_pr=${{ inputs.disable_pr }} \
90+
force_pr_creation=${{ inputs.force_pr_creation }}

0 commit comments

Comments
 (0)