Integrating ChatGPT To Our Codebase For Code Reviewing Purpose

Using GitHub and GitHub Actions

Tolga Taner
4 min readJul 30, 2023
Photo by Cash Macanaya on Unsplash

ChatGPT is an artificial intelligence assistant produced by OpenAI. Although it is currently used in many areas, it has also started to be preferred in the software industry. In this example, I set ChatGPT as a mid-level developer, and it focuses on a few Swift programming language terms. Let’s begin now!

Steps

  • Paying For ChatGPT 3.5-turbo-16k
  • Generating OpenAI API Key
  • Generating GitHub Token
  • Creating A YML File

Paying For ChatGPT 3.5-turbo-16k

Each OpenAI model has the token limitation. As a result, the most recent AI for conversation requires payment. The action returns an error code 400 if we don’t prefer newer versions. I liked ChatGPT 3.5-turbo-16k more. You can certainly check others.

  • Go to https://openai.com/ website and if you already have an account Login or select Sign Up option in the top right corner of the website.
  • Select API from three options in the screen.
  • Select Menu in the top right corner and select Manage Account, add your credit card and pay it. For the duration of my bot testing, each 10 pull requests cost $0.01. But it depends on the size of your pull request and the prompt.

Generating OpenAI API Key

  • Select Menu again, click on View API Keys, generate one key.

It will be used in the action configuration so copy and paste it somewhere.

Generating GitHub Token

  • In GitHub, click your profile photo, then click Settings.
  • In the left sidebar, click Developer Settings.
  • In the left sidebar, under Personal access tokens, click Tokens(classic) and generate it.

Copy and paste it somewhere since we’ll use it in the action when we update the configuration.

Creating A YML File

  • I created a repository and add this YML file to repository’s Actions section without adding any Swift files to the project.
  • This action needs two secrets; GITHUB_TOKEN, OPENAI_API_KEY which we collected from their sources.

My prompt is

“You are a mid level iOS Developer. Check the following diff for just .swift files so Swift codes and tell me if I need to change access control level of the property or the class or there is a missing final keyword somewhere. If it is not, you thank me. Please just say one sentence about it kindly.”

Any time a pull request is opened, synchronize, or reopened, this action is immediately triggered.

I neglected to add a bot account, so you see my review comments instead of the bot. You can either add some script to the YML file or establish a GitHub account for the bot and configure it there. I simply made a pull request to the main branch that we set up and eliminated the commented code on line 28.

Let’s have a look at another Swift programming sample. I create a pull request that includes the default app and a class called Singleton.

In my opinion, it need more project knowledge to mention something about adding the final keyword to the required class.

I still struggle to understand how AI became my colleague. Even if the bot can’t review advanced approaches because of less knowhow, I believe that this will reduce cost of development on any developer. When I consider this logically, there are many benefits to adding ChatGPT to our project as a reviewer, including the fact that the team is crowded, so any team member can spend a lot of time during the code review process, or that anyone can never improve him/herself enough because of small size of members on the project. Those items sound admirable. I suggest that if you want to implement it on your project, check security and cost topics.

Thanks for reading!

--

--