Skip to main content

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+
  • cururo
  • PyGithub
  • requests

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 variable OPENAI_API_KEY)
  • --assistant-id: OpenAI assistant ID (default: environment variable OPENAI_ASSISTANT_ID)
  • --token: GitHub token (default: environment variable GH_TOKEN)
  • --repo: Repository name (default: environment variable REPO)
  • --branch: Branch of work (default: environment variable BRANCH)
  • --gh-before: GitHub before SHA (default: environment variable GH_BEFORE)
  • --sha: Commit SHA (default: environment variable SHA)
  • --message: Commit message (default: environment variable MESSAGE)
  • --webhook: Webhook URL (default: environment variable WEBHOOK)
  • --websecret: Webhook secret (default: environment variable WEBSECRET)

Example Workflow

  1. Prepare the environment: Ensure all required environment variables are set or provide them directly as arguments.

  2. Generate a Git diff: The script will automatically generate a Git diff between the provided SHAs.

  3. Analyze the diff with OpenAI: The script uses OpenAI to analyze the commit message and diff.

  4. 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.

  1. 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
    
  2. 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
    
  3. 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:

  1. Clone the repository
  2. Create a virtual environment: python -m venv venv
  3. Activate the virtual environment:
    • On Windows: venv\Scripts\activate
    • On macOS/Linux: source venv/bin/activate
  4. Install the dependencies: pip install -r requirements.txt
  5. 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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

code_diff_review-2.0.1.tar.gz (7.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

code_diff_review-2.0.1-py3-none-any.whl (8.6 kB view details)

Uploaded Python 3

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

Hashes for code_diff_review-2.0.1.tar.gz
Algorithm Hash digest
SHA256 eb7b809865f424b125db102b5d1b850224054e282a3ef1324dc678b1d109da1a
MD5 121ac3b19f788f0b83683006fdce9e7b
BLAKE2b-256 ba876947ce3e2bba7e03c0a55e935e00f47acd60edaec3ed14a05eb0bfb02d93

See more details on using hashes here.

File details

Details for the file code_diff_review-2.0.1-py3-none-any.whl.

File metadata

File hashes

Hashes for code_diff_review-2.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 888d350869718070220f82795cc7773cd2485dbbca23612bc11333c6a595caa3
MD5 e4331dbeefd6f130f1536d64507c5c74
BLAKE2b-256 b5c330efa3eef125564bf6b7c8066592acf0b4f4e70ab0d78f4175143bebd6a9

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page