Automating Pull Request Review Process with CodiumAI
September 1st, 2024

1 - Introduction

The pull request review review process is a must for building stable products. However, if you have a small engineering team, review process is always the blocker. In a small team, everyone should try to contribute to pull requests reviews, but it is sometimes difficult to understand the context, especially if the PR description lacks the necessary explanations. Therefore, some AI tools might help you to explain your changes to your teammates, get feedbacks for improvements and more! In this article, I will be showing one of those examples, called CodiumAI, which has a very easy setup process with built-in OpenAI support.

2 - Getting OpenAI API Key

What the CodiumAI PR agent does is simply sending your PR context to one of the selected GPT (or other) models and modifying your PR with comments and tags. Since it uses OpenAI as an infra, we should get our API key from OpenAI dashboard first. You can read the following official documentation of OpenAI to learn how you can get the API key very quickly:

After getting an API key, please make sure that your account has enough balance to run APIs.

3 - Whitelisting Models

CodiumAI uses gpt-4o-2024-05-13 model by default. Therefore, you need to whitelist that model on your OpenAI organization.

1 - Go to ProjectLimits

2 - From the Model Usage section, whitelist the models that you want to use (also visible in Figure 1

Figure 1: Whitelisting Model Usage
Figure 1: Whitelisting Model Usage

4 - Adding API Key to GitHub Secrets

After getting an API key, you need to put it to your GitHub secrets to allow your GitHub actions to use it:

1 - Go to your repository settings

2 - Go to SecuritySecrets and VariablesActions

Figure 2: Accessing Repository Secrets
Figure 2: Accessing Repository Secrets

3 - Click to New repository secret

Figure 3: New Repository Secret Creation Button
Figure 3: New Repository Secret Creation Button

4 - Set your secret Name as OPENAI_KEY and value as your API key

Figure 4: Final Step
Figure 4: Final Step

5 - Press Add Secret

Your secret will be created and accessible for workflow usages.

5 - Setting Up GitHub Action

There multiple ways of setting up CodiumAI for your pull requests review. One of the most easiest one is using GitHub actions. The only thing you need to do is setting up the action file on your repository. After that the CodiumAI PR agent will start doing its job.

You need to do the following steps to complete action setup:

1 - Under your repository’s root, create a directory called .github. If it already exists, no action is required

2 - Under .github directory, create another directory called workflows

3 - Create your configuration file with yaml extension under workflows folder. I will call it pr-agent.yaml

In summary, your file structure should be like below, described in Figure 1:

Figure 5: File Structure
Figure 5: File Structure

6 - Workflow Configuration

In the below, the workflow will run in the following cases:

  • Your PR is opened

  • Your PR is reopened

  • Your PR is ready to review

name: PR Agent
on:
  pull_request:
    types: [opened, reopened, ready_for_review]
  issue_comment:
jobs:
  pr_agent_job:
    if: ${{ github.event.sender.type != 'Bot' }}
    runs-on: ubuntu-latest
    permissions:
      issues: write
      pull-requests: write
      contents: write
    name: Run pr agent on every pull request, respond to user comments
    steps:
      - name: PR Agent action step
        id: pragent
        uses: Codium-ai/pr-agent@main
        env:
          OPENAI_KEY: ${{ secrets.OPENAI_KEY }}
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
          github_action_config.auto_review: 'true'
          github_action_config.auto_describe: 'true'
          github_action_config.auto_improve: 'true'

We are setting github_action_config.auto_review, github_action_config.auto_describe and github_action_config.auto_improve settings to automatically run these commands when the PR is opened. Otherwise, you need to run these commands, by commenting to your PR with specific commands.

After opening a PR, you will see that action will run and update your PR’s description, labels and other fields.

You can read more on CodiumAI documentation and explore other ways to run your PR agent:

Subscribe to Farhad
Receive the latest updates directly to your inbox.
Mint this entry as an NFT to add it to your collection.
Verification
This entry has been permanently stored onchain and signed by its creator.
More from Farhad

Skeleton

Skeleton

Skeleton