Review your code diff.
Project description
Code Diff Review
Code Diff Review is a tool to help developers review their code differences by integrating with GitHub and an external API using OpenAI. It generates automated issues and publishes code analysis reports.
Features
- Generate GitHub issues for code diffs
- Integrate with an external API for code analysis
- Publish detailed reports including commit messages, code diffs, and ACID analysis
Installation
You can install the package using pip:
pip install code-diff-review
Requirements
- Python 3.6+
cururoPyGithubrequests
Usage
Command Line Interface
After installation, you can use the code-diff-review command-line tool.
Basic Usage
code-diff-review --openai-key <OPENAI_API_KEY> --assistant-id <OPENAI_ASSISTANT_ID> --token <GH_TOKEN> --repo <REPO> --message <COMMIT_MESSAGE> --gh-before <GH_BEFORE_SHA> --sha <COMMIT_SHA> --branch <BRANCH> --webhook <WEBHOOK_URL> --websecret <WEBSECRET_SECRET>
Arguments
--openai-key: OpenAI API key (default: environment variableOPENAI_API_KEY)--assistant-id: OpenAI assistant ID (default: environment variableOPENAI_ASSISTANT_ID)--token: GitHub token (default: environment variableGH_TOKEN)--repo: Repository name (default: environment variableREPO)--branch: Branch of work (default: environment variableBRANCH)--gh-before: GitHub before SHA (default: environment variableGH_BEFORE)--sha: Commit SHA (default: environment variableSHA)--message: Commit message (default: environment variableMESSAGE)--webhook: Webhook URL (default: environment variableWEBHOOK)--websecret: Webhook secret (default: environment variableWEBSECRET)
Example Workflow
-
Prepare the environment: Ensure all required environment variables are set or provide them directly as arguments.
-
Generate a Git diff: The script will automatically generate a Git diff between the provided SHAs.
-
Analyze the diff with OpenAI: The script uses OpenAI to analyze the commit message and diff.
-
Publish the results: The script publishes the results as a GitHub issue and to a specified webhook.
Detailed Example
Below is a step-by-step example of how you might use the code-diff-review tool in a real scenario.
-
Set environment variables (optional):
export OPENAI_API_KEY=your_openai_key export OPENAI_ASSISTANT_ID=your_assistant_id export GH_TOKEN=your_github_token export REPO=your_repo export MESSAGE="Initial commit" export GH_BEFORE=abc123 export SHA=def456 export BRANCH=branch export WEBHOOK=https://your.webhook.url export WEBSECRET=your_webhook_secret
-
Run the tool:
code-diff-review
Alternatively, you can pass arguments directly:
code-diff-review \ --openai-key your_openai_key \ --assistant-id your_assistant_id \ --token your_github_token \ --repo your_repo \ --message "Initial commit" \ --gh-before abc123 \ --sha def456 \ --branch your_work_branch \ --webhook https://your.webhook.url \ --websecret your_webhook_secret
-
Review the output: The tool will create a GitHub issue with the analysis results and send the same information to the specified webhook.
Development
To contribute to this project, follow these steps:
- Clone the repository
- Create a virtual environment:
python -m venv venv - Activate the virtual environment:
- On Windows:
venv\Scripts\activate - On macOS/Linux:
source venv/bin/activate
- On Windows:
- Install the dependencies:
pip install -r requirements.txt - Make your changes and run the tests.
License
This project is licensed under the MIT License. See the LICENSE file for details.
Author
Agustin Rios - arios6@uc.cl
Changelog
See the CHANGELOG.md file for details on changes in each version.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file code_diff_review-2.0.1.tar.gz.
File metadata
- Download URL: code_diff_review-2.0.1.tar.gz
- Upload date:
- Size: 7.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.9.22
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
eb7b809865f424b125db102b5d1b850224054e282a3ef1324dc678b1d109da1a
|
|
| MD5 |
121ac3b19f788f0b83683006fdce9e7b
|
|
| BLAKE2b-256 |
ba876947ce3e2bba7e03c0a55e935e00f47acd60edaec3ed14a05eb0bfb02d93
|
File details
Details for the file code_diff_review-2.0.1-py3-none-any.whl.
File metadata
- Download URL: code_diff_review-2.0.1-py3-none-any.whl
- Upload date:
- Size: 8.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.9.22
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
888d350869718070220f82795cc7773cd2485dbbca23612bc11333c6a595caa3
|
|
| MD5 |
e4331dbeefd6f130f1536d64507c5c74
|
|
| BLAKE2b-256 |
b5c330efa3eef125564bf6b7c8066592acf0b4f4e70ab0d78f4175143bebd6a9
|