publish action #9
@@ -269,11 +269,8 @@ def main() -> None:
|
||||
)
|
||||
|
||||
parsed_diff = parse_diff(diff)
|
||||
|
||||
comments = analyze_single_chunks(single_chunk_model, parsed_diff)
|
||||
|
||||
full_context_response = analyze_full_context(full_context_model, parsed_diff)
|
||||
|
||||
post_review(full_context_response, comments)
|
||||
|
||||
|
||||
|
||||
21
LICENSE
Normal file
21
LICENSE
Normal file
@@ -0,0 +1,21 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2025 Myeongseon Choi
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
97
README.md
97
README.md
@@ -1,3 +1,96 @@
|
||||
# CodeReviewer
|
||||
# Code Review Action
|
||||
|
||||
AI code reviewer using ChatGPT works on woodpecker CI, Gitea.
|
||||
**Code Review Action** is a Gitea/GitHub Action that automatically reviews pull requests using one or multiple AI Large Language Models (LLMs). It analyzes code diffs and provides both granular file-level feedback as well as an overall review summary.
|
||||
|
||||
## Table of Contents
|
||||
|
||||
- [Features](#features)
|
||||
- [Usage](#usage)
|
||||
- [Inputs](#inputs)
|
||||
- [Example Workflow](#example-workflow)
|
||||
- [License](#license)
|
||||
|
||||
---
|
||||
|
||||
## Features
|
||||
|
||||
- **Single Chunk Review**: The action analyzes each file’s diff and provides line-specific suggestions (if applicable).
|
||||
- **Full Context Review**: Analyzes entire file contents plus diffs, giving an overall code review summary.
|
||||
- **Configurable Models**: Supports multiple LLM providers (OpenAI, Anthropic, Google, etc.) via model prefixes (`gpt-`, `claude-`, `gemini-`, `deepseek-`).
|
||||
- **Exclusion Filters**: Skip certain files (e.g. `.yaml`) based on matching patterns.
|
||||
|
||||
---
|
||||
|
||||
## Usage
|
||||
|
||||
1. **Add this Action** to your repository’s workflow (e.g., `.github/workflows/pr-review.yml` or `.gitea/workflows/pr-review.yml` in Gitea).
|
||||
2. **Provide required inputs** (API keys, model names, etc.) as shown below.
|
||||
3. **Submit a pull request** against the repository. The Action will automatically run on PR events (`opened` or `synchronize`) and post review comments.
|
||||
|
||||
> **Note**: This action is intended primarily for use with Gitea.
|
||||
|
||||
---
|
||||
|
||||
## Inputs
|
||||
|
||||
| Input Name | Required | Default | Description |
|
||||
|-------------------------|----------|----------------|---------------------------------------------------------------------------------------------------------|
|
||||
| `access-token` | Yes | - | The Gitea or GitHub token with permissions to read and comment on PRs (e.g., `$GITHUB_TOKEN`). |
|
||||
| `full-context-model` | Yes | `gpt-4o` | The model to use for the full context review. Supports prefixes: `gpt-`, `claude-`, `gemini-`, etc. |
|
||||
| `full-context-api-key` | Yes | - | The API key to use with the specified full-context model. |
|
||||
| `single-chunk-model` | Yes | `gpt-4o` | The model to use for single-chunk review (file-by-file). |
|
||||
| `single-chunk-api-key` | Yes | - | The API key to use with the specified single-chunk model. |
|
||||
| `exclude-files` | No | `*.yml,*.yaml` | Comma-separated file pattern(s) to exclude from diffs (e.g., `*.md,*.yaml`). |
|
||||
|
||||
---
|
||||
|
||||
## Example Workflow
|
||||
|
||||
Below is an example workflow file you can place in your repository (e.g., `.github/workflows/pr-review.yml` on GitHub or `.gitea/workflows/pr-review.yml` on Gitea). Adjust the version/tag/branch reference as needed.
|
||||
|
||||
```yaml
|
||||
name: PR Review
|
||||
|
||||
on:
|
||||
pull_request:
|
||||
types: [opened, synchronize]
|
||||
|
||||
permissions:
|
||||
contents: read
|
||||
pull-requests: write
|
||||
|
||||
jobs:
|
||||
review:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: AI Code Review
|
||||
uses: YOUR-ORG/CODE-REVIEW-ACTION@v1
|
||||
with:
|
||||
access-token: ${{ secrets.ACCESS_TOKEN }}
|
||||
full-context-model: "gpt-4o"
|
||||
full-context-api-key: ${{ secrets.OPENAI_API_KEY }}
|
||||
single-chunk-model: "claude-3-5-sonnet-20240620"
|
||||
single-chunk-api-key: ${{ secrets.ANTHROPIC_API_KEY }}
|
||||
exclude-files: "*.md,*.yaml"
|
||||
```
|
||||
|
||||
### Explanation
|
||||
|
||||
1. **`on.pull_request.types`**: The workflow triggers when a pull request is opened or synchronized (i.e., new commits pushed).
|
||||
2. **`permissions`**: We grant `read` permission to contents and `write` to pull-requests so the Action can post review comments.
|
||||
3. **`steps.uses`**: References your published action. Replace `YOUR-ORG/CODE-REVIEW-ACTION@v1` with the actual owner/repo name and a valid version tag (e.g., `@main` or `@v1`).
|
||||
4. **`with`**: Provides the necessary inputs.
|
||||
- `access-token`: Must be a secret that can post to PRs (e.g., `$GITHUB_TOKEN` or a personal access token on Gitea).
|
||||
- `full-context-model` & `single-chunk-model`: Choose which models to use (OpenAI GPT, Anthropic Claude, Google PaLM, etc.).
|
||||
- `full-context-api-key` & `single-chunk-api-key`: Corresponding API keys for each model.
|
||||
- `exclude-files`: If you want to skip reviewing certain file types, specify patterns here (default is `*.yml,*.yaml`).
|
||||
|
||||
---
|
||||
|
||||
## License
|
||||
|
||||
This project is available under the [MIT License](LICENSE). Feel free to modify and adapt to your own needs.
|
||||
|
||||
---
|
||||
|
||||
If you have any questions, issues, or feedback, please [open an issue](../../issues) in this repository. Happy reviewing!
|
||||
54
action.yml
Normal file
54
action.yml
Normal file
@@ -0,0 +1,54 @@
|
||||
name: "Code Review Action"
|
||||
description: "An action that reviews PR changes using multiple AI LLMs."
|
||||
author: "Myeongseon Choi"
|
||||
|
||||
inputs:
|
||||
access-token:
|
||||
required: true
|
||||
description: "Gitea or GitHub token"
|
||||
full-context-model:
|
||||
required: true
|
||||
default: "gpt-4o"
|
||||
description: "Model for the full context pass"
|
||||
full-context-api-key:
|
||||
required: true
|
||||
description: "API key for the full context model"
|
||||
single-chunk-model:
|
||||
required: true
|
||||
default: "gpt-4o"
|
||||
description: "Model for the file-chunk pass"
|
||||
single-chunk-api-key:
|
||||
required: true
|
||||
description: "API key for the single chunk model"
|
||||
exclude-files:
|
||||
required: false
|
||||
default: "*.yml,*.yaml"
|
||||
description: "Patterns to exclude in diffs"
|
||||
|
||||
|
||||
runs:
|
||||
using: "composite"
|
||||
steps:
|
||||
- name: Check out code
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Set up Python
|
||||
uses: actions/setup-python@v5
|
||||
with:
|
||||
python-version: "3.12"
|
||||
|
||||
- name: Install dependencies
|
||||
run: |
|
||||
python -m pip install --upgrade pip
|
||||
pip install requests py-gitea openai anthropic google-generativeai
|
||||
|
||||
- name: Run Code Review
|
||||
shell: bash
|
||||
env:
|
||||
ACCESS_TOKEN: ${{ inputs.access-token }}
|
||||
FULL_CONTEXT_MODEL: ${{ inputs.full-context-model }}
|
||||
FULL_CONTEXT_API_KEY: ${{ inputs.full-context-api-key }}
|
||||
SINGLE_CHUNK_MODEL: ${{ inputs.single-chunk-model }}
|
||||
SINGLE_CHUNK_API_KEY: ${{ inputs.single-chunk-api-key }}
|
||||
EXCLUDE: ${{ inputs.exclude-files }}
|
||||
run: python .gitea/scripts/code_review.py
|
||||
Reference in New Issue
Block a user