A Helper Agent That Became My Friend

fahimfba

Md. Fahim Bin Amin

Posted on December 4, 2023

A Helper Agent That Became My Friend

The title seems pretty intuitive and clickbait, right? But I promise that it isn't!

As an open-source contributor, I struggle to check out all the GitHub notifications I get each hour. Sometimes, it burns me out to check them on a daily basis, and I also get a lot of notifications from people complaining about not checking their issues or pull requests.

Pull requests are one of the most important things in our lives if we are developers. Pull requests can contain a fix of a bug that you have been struggling to resolve for a very long time. Pull requests can contain new enhancement features, documentation, and a lot of things that can not be described in sentences.

As for me, I find pull requests need more attention than the issues themselves. Why is that? Let me clarify.

Pull requests indeed require significant attention in the software development process. Here are a few reasons why they might demand more focus than issues:

  1. Complexity: Pull requests often involve changes across multiple files or even entire systems. They may include multiple solutions or features, making them more intricate than individual issues.

  2. Code Quality and Review: Pull requests necessitate thorough code reviews to ensure the quality, correctness, and adherence to coding standards. This involves analyzing the changes made, checking for bugs, and ensuring that the code integrates smoothly with the existing codebase.

  3. Integration and Testing: Pull requests need to be integrated into the main codebase seamlessly. This involves running various tests to ensure that the changes do not introduce new bugs or regressions.

  4. Collaboration and Discussion: Pull Requests are often the focus of collaboration between team members. Discussions, suggestions, and improvements might occur within the PR itself, making it a focal point for teamwork and iteration.

  5. Impact on the Project: Unlike issues, which often describe problems or feature requests, pull requests directly implement changes. Their impact on the project can be more profound, making careful attention essential.

  6. Merge Process: Before merging a pull request, it's essential to consider the implications it might have on the codebase and the project as a whole. Handling conflicts and ensuring a smooth merge is critical.

While issues define problems or tasks, pull requests represent the proposed solutions or changes to address those issues. Hence, they demand more attention due to their direct influence on the codebase and the project's progress.

As we need to do most of the tasks manually in the pull requests, it takes a lot of time and effort to check them.

What if we had an Artificial Intelligence agent that does the job for us? That sounds interesting, in fact too amazing and too good to be true, right?

Well, luckily for me, I have already found an interesting tool that does exactly what I struggle to do in the pull requests. That is none other than the PR Agent of Codium AI.

Website for the Git Plugin of CodiumAI

Now, I know that a lot of you are thinking about the existing GitHub copilot. Don't get me wrong, I was there too. I was an avid Copilot user, but after checking out CodiumAI, I have become their fan, to be honest. The detailed comparison can take a lot of pages here, but I am going to make it simple so that you can get to know the differences at a glance.

GitHub Next (Copilot for Pull Request) PR Agent of Codium AI
Closed Source Open Source
Limited amount of commands Supports many commands
Supports only GitHub Supports all Git platforms
Supports GitHub only Supports GitHub and IDEs

How To Add Codium AI's PR Agent Into Your GitHub Repository

There are many ways to add the PR agent to your new or existing GitHub repository, but I find it useful to do that as a GitHub action. If you are interested in checking the other available installation methods, then you can simply head over to their official documentation where they described each of them really well.

I will specifically show the hands-on procedure of how you can do that too.

  • You have to create a .github directory in your repository's root directory. In that .github directory/folder, you can create another sub-directory/folder named workflows which is useful especially when you are planning to use multiple workflows in a repository. For the sake of this article, I am creating a brand new repository named test-pr-agent on GitHub. Creating a new GitHub repository Creating a new GitHub repository
  • The new repository has been created. A new GitHub repository
  • For all of the later tasks, you can directly use your browser and make the changes, or you can also open the VSCode dev edition on your browser/codespace. You can also make the changes locally after cloning the repository. I like to work on local machines, therefore, I will clone the repository and make the changes.
  • For cloning my repository, I would simply copy the SSH URL. Clone using SSH
  • Now I will open my terminal. You can use any terminal you want. Then you can also change the directory if you want to clone the repository in a different location. For example, I am changing my current directory to the Desktop as I want to clone the repository in my Desktop directory. Changing the current directory to the Desktop
  • Make sure that you already have configured your local machine for GitHub usage, like installing Git if you are on Windows, adding the SSH keys, and so on. To clone the repository, I can simply use the git clone SSH-URL command. For me, it is git clone git@github.com:FahimFBA/test-pr-agent.git Cloning the repository in the local machine
  • As I already have the VS Code installed on my local machine, I can simply open the VS Code in that cloned repository's directory. Opening VS Code
  • For now, I am creating a new yml file under .github/workflows/. I am naming the file as pr_agent.yml. You can give it other names if you want, but you can not keep space between the words in the file name. After this, the file is residing within .github/workflows/pr_agent.yml.
  • Now I can copy the relevant lines of code from the official documentation.
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 }}
Enter fullscreen mode Exit fullscreen mode
  • Now I can simply commit the changes and push to the origin.
  • Maybe you can already understand that we need to enable the GitHub action to write settings on the repository. We also need to generate our OpenAI Key and add that as a repository secret in the GitHub repository.
  • Every GitHub repository has a specified GitHub token, and that is generally used as GITHUB_TOKEN in the code. But we need to enable the write access from that specific repository settings. To do that, simply head over to the GitHub repository in your browser, and go to the Settings tab. Go to repository settings
  • Click on the Actions menu and then click on the General submenu. GitHub action settings
  • Make sure that you have selected Allow all actions and reusable workflows within the Actions permission section. Actions permission
  • You can keep the Fork pull request workflows from outside collaborators section as it was. I keep it in Require approval for first-time contributors. Fork pull request workflows from outside collaborators section
  • Make sure to select Read and write permissions within the Workflow permissions section. Workflow permissions Also, make sure that you have added a tick (✅) mark in the Allow GitHub Actions to create and approve pull requests section.
  • Click Save to save all newly customized settings.
  • Now we need the API Key from OpenAI. Simply head over to the official website to get the API key. Login to your OpenAI/ChatGPT account.
  • We need to generate a new secret API key to use in that repository. Simply click on "Create new secret key". Create new secret key
  • Give a name to your new secret key so that you can understand afterward which key you used for the PR-agent. Name your secret key For me, let me name it "PR-agent secret key". Then click on "Create secret key". This will provide you with a new secret key. Make sure to copy it, as we need it right after this. Also, it is a sensitive key, therefore, make sure no one else gets to know this key. For security purposes, I have also tried to hide the key. My Secret key Click on "Done".
  • Now head over to your repository where you have added the yml file to use the PR-agent. Go to the repository settings, Click on "Secrets and variables" and lastly click on "Actions". repo actions
  • Click on "New repository secret". repo secret
  • Now paste your OpenAI Secret key in the Secret box and give it a name that you used in the yml file. As I used OPENAI_KEY as the variable name in the yml file, I am going to give the same name here as well. my repo secret for the OpenAI key
  • Click on "Add secret". Now you are good to go!

Let us test it out!

Now it is the time to check whether that is working or not. For simplicity, I am creating a new branch locally where I am making some changes. Later I am going to add a new pull request.

New PR

Now you see that the PR-Agent has already started working in the PR.

actions on the go

I can call the CodiumAI-Agent by mentioning it with a @ and I can pass the pre-defined commands. For now, let's see what it reviews on the new pull request.

I can simply use @CodiumAI-Agent /review, and then click on "Comment".

The PR-agent has started working instantly, and I can also check that from the Actions > Workflows tab.

PR-agent has started working

Now you see that the PR-agent has responded to my comment with an eye emoji (👀), and it immediately provided me with its review. It also gives feedback, how to use, instructions, etc. data so that others can also use it.

After calling once, the PR-agent would become available in the mentions, and you can call it using the @.

Call the PR-agent

Currently available commands for the PR-agent are:

You can tag @CodiumAI-Agent in a comment '@CodiumAI-Agent' and add one of the following commands:
/review: Request a review of your Pull Request.
/describe: Update the PR title and description based on the contents of the PR.
/improve [--extended]: Suggest code improvements. Extended mode provides a higher quality feedback.
/ask <QUESTION>: Ask a question about the PR.
/update_changelog: Update the changelog based on the PR's contents.
/add_docs: Generate docstring for new components introduced in the PR.
/generate_labels: Generate labels for the PR based on the PR's contents.
You can also see the tools guide for more details.

I love asking questions using this!

A silly conversation

On a serious note

Enough chatting! Now it is the time to test it in action. I am working on a project named AssistMe.

Now I am going to integrate PR-agent into this existing repository, and then I am going to check whether it performs well on the older Pull Requests.

Voila! 🎊

It also works with the earlier pull requests.

Code feedback

old PR 2

old PR 3

Conclusion

Thanks for reading the entire article. Now you see how I scaled up my open source project progress and made myself more productive while CodiumAI's PR-Agent is doing my task for me more efficiently!

It's really a blessing to have this type of AI tool for us. Surprisingly enough, CodiumAI's PR-agent also offers a free tier, and the examples I have shown above, all of them have been done using the free tier account. So, just think how many things can be done if you want to scale it more!

This is it for today. Hope to see you again someday.

Cheers! 🥂

Cover Image Credit: Photo by Kenny Eliason on Unsplash

💖 💪 🙅 🚩
fahimfba
Md. Fahim Bin Amin

Posted on December 4, 2023

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related