Skip to content
code

GitHub Action

CodeGPT PR Assistant

v1.0.0 Latest version

CodeGPT PR Assistant

code

CodeGPT PR Assistant

A helpful assistant that reviews pull requests and provides code suggestions

Installation

Copy and paste the following snippet into your .yml file.

              

- name: CodeGPT PR Assistant

uses: isat/[email protected]

Learn more about this action in isat/codegpt

Choose a version

CodeGPT PR Assistant

Description

The CodeGPT PR Assistant is a GitHub Action designed to review pull requests and provide code suggestions, helping developers improve their code quality and consistency. It integrates with GitHub Actions to automatically analyze and comment on new pull requests and commits.

Features

  • Review pull request changes automatically.
  • Provide feedback and code suggestions.

Required ENV variables

  • OPENAI_API_KEY: The OpenAI API key needed to interact with language models. This var is required.
  • GITHUB_TOKEN: The GitHub API key needed to interact with GitHub's API. Usually available on your env. This var is required.

Inputs

  • OPENAI_ASSISTANT_ID: The ID of the OpenAI assistant being used. This input is required.

Outputs

  • response: The output message from processing the event, which includes feedback or code suggestions based on the pull request content.

Usage

To use this action in your GitHub workflows, add the following step:

name: Ask CodeGPT for feedback

on:
  pull_request:
    types: [opened]
  issue_comment:
    types: [created]

jobs:
  process-events:
    runs-on: ubuntu-latest
    steps:
      - name: Run CodeGPT
        if: github.event_name == 'pull_request' || (github.event_name == 'issue_comment' && contains(github.event.comment.body, 'CodeGPT') && !contains(github.event.comment.body,'The following is a message from CodeGPT:'))
        uses: isat/[email protected]
        with:
          OPENAI_ASSISTANT_ID: 'YOUR_ASSISTANT_ID_GOES_HERE'
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
          OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }}

Don't forget to enable Read and Write permissions on your Repo/Org's Workflow permissions if you haven't already.

Each repo can also have a CODEGPT.md file, which will be passed as context to the Bot.

These are the recommended base instructions for your assistant.

You will be resposible for reviewing pull requests. File by file, you will analyze changes and point out improvements to be made.

In terms of Evaluation, we consider that NeedsImprovement is the first failing evaluation. Something with minor issues can be passed as Acceptable, and something that could be better but isn't bad might be Very Good. Do not fail a commit just because it has an inconsistent newline or is missing a newline at the end of the file.

You are not to point out whitespace errors at all, like lack of newlines at the end of files, too many newlines, inconsistent indentation or any other sort of whitespace error. You are also not to point out issues with the formatting of the diffs, since those aren't generated by the user.

When I ask you something, I will specify the interface you shall use in your JSON response.

These can be adjusted to give the assistant a personality, or to pay more attention to a specific value. For each specific request, there is also context that is passed, available on the source code. You can fork this repo to change this specific context.

How it works

This GitHub Action uses Open AI's Assistants behind the scenes, which are, at the time of writing this, a beta feature. Assistants are a way to interact with the API the same way we interact with ChatGPT, managing chat Threads and pruning the context for us. This project coerces the output to JSON and tells the assistant how to format the output, which gives consistent results in the requested schema.

To better manage the context, the Action splits the PR into multiple parts:

image

Each of these parts is analyzed in a different thread, concurrently. This both speeds up analysis and keeps the context short for each request.

To make sure we get relevant feedback, we coerce the assistant to give feedback in a specific schema, which can be visualized globally below:

image

The global flow is summarized below:

image