Automatic Code Review
This repository uses GitHub Actions for automatic code review on every Pull Request. The code review process is powered by the auto-code-review library, which connects to the OpenAI API to generate inline comments and suggestions for code improvements.
GitHub Actions Configuration
Below is the configuration for the GitHub Actions workflow:
name: Auto Code Review
on:
pull_request:
types: [opened, synchronize, reopened]
branches:
- '*'
jobs:
pr_review:
runs-on: ubuntu-latest
permissions:
contents: write
pull-requests: write
steps:
- name: Check out repository
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: "3.12"
- name: Install auto-code-review from PyPi
run: |
python -m pip install --upgrade pip
pip install auto-code-review
- name: Run auto code review
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }}
GITHUB_HEAD_REF: ${{ github.head_ref }}
GITHUB_BASE_REF: ${{ github.base_ref }}
REPO_OWNER: ${{ github.repository_owner }}
REPO_NAME: ${{ github.event.repository.name }}
PULL_NUMBER: ${{ github.event.number }}
run: auto-code-review --config config.yaml
How It Works
- Trigger on
pull_request: The workflow is triggered when a Pull Request is created, updated, or reopened. - Set Up Python Environment: The workflow sets up Python version
3.12and installs theauto-code-reviewpackage from PyPI. - Run Auto Code Review: The
auto-code-reviewcommand is executed to analyze the changes in the Pull Request using OpenAI’s API. The tool will leave inline comments on the code changes with potential issues.
Prerequisites
Before using this workflow, you need to add the following secrets to your repository settings:
GITHUB_TOKEN: A GitHub token automatically provided in your repository (no extra setup needed).OPENAI_API_KEY: Your OpenAI API key, which must be added manually inSettings->Secrets and variables->Actions->New repository secret.
Example Usage
To enable automatic code review, simply create a Pull Request from any branch in your repository which contains the needed worklflow file. GitHub Actions will automatically trigger the analysis, and inline comments will be added directly to the Pull Request with feedback on code style, potential optimizations, and any detected issues.
Additional Notes
- This workflow supports any branch (
branches: ['*']), meaning it will run for Pull Requests involving any target branch. - The tool is configured via a
config.yamlfile, which should be present in the root directory of your repository. This file allows you to specify various settings such as the AI model, temperature and file extensions
Sample Config File (config.yaml)
# config.yml
analysis:
file_extensions:
.py: "PEP8"
.cpp: "Google Code Style"
ai_settings:
ai_model: gpt-4o-mini
temperature: 0.7
max_tokens: 1000
In this configuration:
ai_modelsets the chatgpt model which will be used to create comments(gpt-4o-mini by default)file_extensionssets the extensions of files which will be auto-reviewed(Necessary to write extensions)temperaturecontrols the randomness of the suggestions - higher values make responses more creative(0.7 by default).max_tokenslimits the number of tokens generated by the AI.(1000 by default)
Troubleshooting
If the workflow fails with a 422 Unprocessable Entity error, it could be due to:
- An incorrect
positionvalue for inline comments. - An invalid or outdated
commit_id. - Missing or incorrect
pathfor the file being commented on.
Ensure that your configuration and API keys are set up correctly, and check the logs in GitHub Actions for more details.
Metadata
Release files for auto-code-review 0.1.5
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| auto_code_review-0.1.5.tar.gz | 10.6 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| auto_code_review-0.1.5-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 21.2 kB
Release files / auto_code_review-0.1.5.tar.gz
| Download URL | auto_code_review-0.1.5.tar.gz |
|---|---|
| Size | 10.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
266ed770c7fc734f215f005a0d81634189f91fcb5576e32eb023b051fb7b5eb1
|
|
BLAKE2b-256 checksum How to use checksums |
a1387e5508f2298fb4512e94f83889683e5659a762dad1a390f4f4d56959914d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.1.1 CPython/3.12.6
|
Release files / auto_code_review-0.1.5-py3-none-any.whl
| Download URL | auto_code_review-0.1.5-py3-none-any.whl |
|---|---|
| Size | 10.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
8ab1365264c2e2576a283f1257aaf89b3e2c42c7ca136007a1be7a010a3ae25e
|
|
BLAKE2b-256 checksum How to use checksums |
65809767aa38d7b21ac6e61c843868f6c8da2f167b3157dc9c84b0f0785eb96c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.1.1 CPython/3.12.6
|
Security for auto-code-review 0.1.5
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.