Skip to content

Commit 1f2bad2

Browse files
committed
Generate base github action
0 parents  commit 1f2bad2

File tree

2 files changed

+187
-0
lines changed

2 files changed

+187
-0
lines changed

README.md

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
# Patched PRReview Action
2+
3+
This GitHub Action uses [patchwork-cli](https://docs.patched.codes/patchwork/quickstart) to automatically summarize and comment on PRs in your repository.
4+
5+
## Features
6+
7+
- Automatically reviews and summarizes pull requests
8+
- Generates improvement suggestions for the PR (optional)
9+
- Configurable summary length (long, short, none)
10+
- Supports various LLM providers (OpenAI, local models, or custom endpoints)
11+
- Automatic PR detection in GitHub Actions workflows
12+
13+
## Usage
14+
15+
```yaml
16+
name: PR Review
17+
on:
18+
pull_request:
19+
types: [opened]
20+
21+
jobs:
22+
review:
23+
runs-on: ubuntu-latest
24+
steps:
25+
- uses: patched-codes/[email protected]
26+
with:
27+
patched_api_key: ${{ secrets.PATCHED_API_KEY }}
28+
# PR URL is automatically detected in pull_request events
29+
```
30+
31+
## Inputs
32+
33+
### Required
34+
35+
One of the following must be provided:
36+
37+
- `patched_api_key`: Patched API key for the LLM ([Get an API key](https://app.patched.codes/))
38+
- `openai_api_key`: OpenAI API key for the LLM ([Get an API key](https://platform.openai.com/account/api-keys))
39+
40+
### Optional
41+
42+
- `pr_url`: URL of the pull request to review (default: automatically detected in pull_request events)
43+
- `github_token`: GitHub token for creating PR comments (default: [Automatically set by GitHub](https://docs.github.com/en/actions/security-for-github-actions/security-guides/automatic-token-authentication))
44+
- `model`: LLM model to use
45+
- `client_base_url`: Base URL for the LLM API
46+
- `diff_suggestion`: Whether to generate suggestions to improve the PR
47+
- `diff_summary`: Length of the summary (long, short, none)
48+
- `model_temperature`: Temperature parameter for the LLM
49+
- `model_top_p`: Top-p parameter for the LLM
50+
- `model_max_tokens`: Maximum tokens for the LLM response
51+
52+
## Examples
53+
54+
### Basic Usage
55+
56+
```yaml
57+
- uses: patched-codes/[email protected]
58+
with:
59+
patched_api_key: ${{ secrets.PATCHED_API_KEY }}
60+
```
61+
62+
### Manual PR Review
63+
64+
```yaml
65+
- uses: patched-codes/[email protected]
66+
with:
67+
patched_api_key: ${{ secrets.PATCHED_API_KEY }}
68+
pr_url: "https://github.com/user/repo/pull/123"
69+
diff_suggestion: true
70+
diff_summary: "long"
71+
```
72+
73+
### Using Custom Model
74+
75+
```yaml
76+
- uses: patched-codes/[email protected]
77+
with:
78+
openai_api_key: ${{ secrets.OPENAI_API_KEY }}
79+
model: "gpt-4"
80+
model_temperature: 0.2
81+
model_top_p: 0.95
82+
model_max_tokens: 2000
83+
```
84+
85+
## Example Comments
86+
87+
Here are some example comments generated with the PRReview action:
88+
89+
- https://github.com/patched-codes/patchwork/pull/59#issuecomment-2092735385
90+
- https://github.com/patched-codes/patchwork/pull/56#issuecomment-2092584306
91+
92+
## License
93+
94+
MIT
95+
96+
## Contributing
97+
98+
Contributions are welcome! Please feel free to submit a Pull Request.

action.yml

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
name: 'Patched PRReview'
2+
description: 'Automatically summarize and comment on PRs in your repository'
3+
branding:
4+
icon: 'git-pull-request'
5+
color: 'orange'
6+
author: '@patched-codes'
7+
8+
inputs:
9+
github_token:
10+
description: 'GitHub token for creating pull requests'
11+
required: false
12+
default: ${{ github.token }}
13+
openai_api_key:
14+
description: 'OpenAI API key for the LLM'
15+
required: false
16+
pr_url:
17+
description: 'URL of the pull request to review'
18+
required: true
19+
default: ${{ github.event.pull_request.html_url }}
20+
model:
21+
description: 'LLM model to use'
22+
required: false
23+
client_base_url:
24+
description: 'Base URL for the LLM API'
25+
required: false
26+
diff_suggestion:
27+
description: 'Whether to generate suggestions to improve the PR'
28+
required: false
29+
diff_summary:
30+
description: 'Length of the summary (long, short, none)'
31+
required: false
32+
model_temperature:
33+
description: 'Temperature parameter for the LLM'
34+
required: false
35+
model_top_p:
36+
description: 'Top-p parameter for the LLM'
37+
required: false
38+
model_max_tokens:
39+
description: 'Maximum tokens for the LLM response'
40+
required: false
41+
42+
outputs:
43+
comment_url:
44+
description: 'URL of the created PR comment'
45+
value: ${{ steps.pr-review.outputs.comment_url }}
46+
47+
runs:
48+
using: 'composite'
49+
steps:
50+
- name: Set up Python
51+
uses: actions/setup-python@v4
52+
with:
53+
python-version: '3.x'
54+
55+
- name: Restore pip cache
56+
uses: actions/cache@v3
57+
with:
58+
path: ~/.cache/pip
59+
key: ${{ runner.os }}-pip-patchwork-cli
60+
restore-keys: |
61+
${{ runner.os }}-pip-patchwork-cli
62+
63+
- name: Install dependencies
64+
shell: bash
65+
run: |
66+
python -m pip install --upgrade pip
67+
pip install patchwork-cli
68+
69+
- name: Generate config
70+
shell: bash
71+
run: |
72+
cat > config.yml << EOF
73+
github_api_key: "${{ inputs.github_token }}"
74+
$([ -n "${{ inputs.openai_api_key }}" ] && echo "openai_api_key: \"${{ inputs.openai_api_key }}\"")
75+
$([ -n "${{ inputs.pr_url }}" ] && echo "pr_url: \"${{ inputs.pr_url }}\"")
76+
$([ -n "${{ inputs.model }}" ] && echo "model: \"${{ inputs.model }}\"")
77+
$([ -n "${{ inputs.client_base_url }}" ] && echo "client_base_url: \"${{ inputs.client_base_url }}\"")
78+
$([ -n "${{ inputs.diff_suggestion }}" ] && echo "diff_suggestion: ${{ inputs.diff_suggestion }}")
79+
$([ -n "${{ inputs.diff_summary }}" ] && echo "diff_summary: \"${{ inputs.diff_summary }}\"")
80+
$([ -n "${{ inputs.model_temperature }}" ] && echo "model_temperature: ${{ inputs.model_temperature }}")
81+
$([ -n "${{ inputs.model_top_p }}" ] && echo "model_top_p: ${{ inputs.model_top_p }}")
82+
$([ -n "${{ inputs.model_max_tokens }}" ] && echo "model_max_tokens: ${{ inputs.model_max_tokens }}")
83+
EOF
84+
85+
- name: Run PRReview
86+
id: pr-review
87+
shell: bash
88+
run: |
89+
patchwork PRReview --config config.yml

0 commit comments

Comments
 (0)