Exploring Codium GitHub Pull Request AI Assistant
Tags: ai, developers, codereview
Published: 2023-12-27 08:58:25

I work in a software development and consulting firm and a large portion of my day is spent reviewing pull requests from different projects. Pull requests a.k.a merge requests are the contributions done by the engineers, generally covered by the unit tests. 

My job is to ensure the pull requests follow our standards and do the review of the code or delegate to one of the architects to review it if my plate is full or I am busy with some other work. 

Here are some of the standards that I make sure everyone is following:

- The Jira ticket link is mentioned in the PR title.
- The ticket description is not vague or one-liners and explains the changes and how it is tested.
- Unit test coverage (more than 80%).

And some more project-related details. Every developer in my team always cries over filling in all these details and they always say “Look at the code”. I  understand this frustration as I used to bash the same to my seniors. 

I use Github copilot and some of my team members also use the same. It’s a fantastic tool that provides real-time code suggestions and helps us write code/tests faster. 

GitHub announced copilot for PR and we were excited about it. While this is on the waiting list and should be available soon, I got the article suggestion on **dev.to** platform about a similar tool, opened the article and was astonished to know that the team at Codium has already done this, and they did it better!

After reading and using the Codium PR description for a day, I wanted to document and write a blog about it for fellow developers and engineers.

## Making Pull Requests Less Painful Using Codium PR AI Agent
Codium AI and Github Copilot both use artificial intelligence to assist developers in writing better pull request descriptions and titles, detecting security flaws and much more. 

One of the key differences between them is that Codium provides open-source solutions that can be integrated into our infrastructure. This is a major advantage over Github because the cost of a subscription to Copilot is high when you have a team of say 20 developers.

There are other key differences as well and they are the key factors why you should consider Codium like I did over GitHub PR tool. 

One major difference is that Codium supports all Git-based platforms. I have many clients who use self-hosted Gitlab and they just simply cannot use Copilot because it’s supported only on GitHub. This was one of the key reasons why we started researching such tools. 

The open-source version of the [Codium PR agent](https://github.com/Codium-ai/pr-agent#Quickstart) is one of the best approaches to using Codium in the infrastructure maintained by the team.  We used the docker image to install this and it was easy as cake! There are other ways to install as well so you are not limited by options. 

## How PR Agent Works
Here is the detailed diagram from the official Codium website.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/7wyle2egxpz0yo6ez3qd.png)
Once the PR agent is installed in Github or any supported Git-based software. You can invoke the PR agent by using different commands such as:

- /review - Reviews the PR and provides you with gist information.
- /describe - generates a description of the PR.
- /ask ? - ask any question such as “suggest any fixes”

And more.

The GitHub PR tool will provide a similar experience and we will know more about it once it’s live for everyone. I would rather recommend using Codium because of its seamless integration within a system and provides support to almost all programming languages. 

## Using PR Agent in Github

Let’s try to use Codium’s PR agent in GitHub and see how it adds value to our workflow. I am going to use a public repo in my profile to show you how it works. For the demo, we are going to use the pre-described Codium PR Agent image in the GitHub actions. 

You can refer to the documentation [here](https://github.com/Codium-ai/pr-agent/blob/main/INSTALL.md#run-as-a-github-action) as you follow the article. 

First thing, create a **.github/workflow** folder in the code repository. Inside the **workflow** folder, create a file named **pr_agent.yml** and place this code. 

```on:
  pull_request:
  issue_comment:
jobs:
  pr_agent_job:
    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 }}
```
You need an openAI API key, you can obtain it by signing up here and creating an API key. 

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/uc1apl8r6f0ukn9bn1xh.png)

Now, take the API key and open the **Settings** page of your GitHub repository. Go to **Secrets** and **Variables -> Actions**. Here create a new repository access add the key name **OPENAI_KEY** and place your openAI API key. 

There you go, now we can use the Codium PR agent. The Github token will be created automatically by Github so we don’t need to worry about it. 

Now go ahead and create a pull request in your repository. Once your pull request is created, the PR agent will automatically add a comment mentioning a bit of detail. Here is the screenshot for reference. 


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/e2f8q5k5sg887uhm4u5k.png)

Now, let’s see how the PR agent can provide us with more details. To add PR agent commands, we need to add a command with the commands in it. 

I am adding the first command as /describe and the PR agent will generate and add a comment to the pull request as an output.


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/6dgorhwsnipn0v72fhla.png)

Here is the output.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/muilieswizbdcpu1i7x3.png)

Awesome!

Now, let’s generate labels for this pull request. Add **/generate_labels** to the comment box and let the PR agent do the magic. 


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/fxthpnvamiclujja4p1g.png)

PR agent automatically analyzed and added the label Tests to the pull request. 

Let’s try another command and try to generate the changelog. Add **/update_changelog** and you should have a comment added as an output.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/juz6jd0awf7qmfk84ey6.png)

Go ahead and explore more commands and use the power of Codium’s PR agent to enhance your workflow.

## Pricing

This is where it gets more interesting. Codium PR agent as I mentioned earlier is open source and can be used in any git-supported platform such as Gitlab, Github, etc. It’s free to use and you only need to configure your openAI API key. It’s way cheaper than GitHub for sure. 

## Data Privacy

Codium doesn’t store any communication data. Since it’s linked with OpenAI, the communication between your PR instance and openAI is with you and not with Codium. 

## Conclusion
AI solutions are one of the great productivity contribution elements in software development fields. We want to ensure that the majority of hours of developers are involved in writing good code and the rest is metadata work.  Assisting and automating the developer workflow will save so many hours and cost and the Codium PR tool is one of those tools which is a game changer.