Mastering PR Messages: Why worry about them when there's AI (Part 2)

tecnosam

Samuel Abolo

Posted on December 8, 2023

Mastering PR Messages: Why worry about them when there's AI (Part 2)

Content

  1. Introduction
  2. Scenario
  3. PR messages with GitHub Copilot
  4. PR messages with CodiumAI
  5. Which is better?
  6. Conclusion

Introduction

Let's face it. We're developers. We all want to ship fast. When that new feature is requested or that issue is raised, we want to get it checked out ASAP and focus on other things. We hate the extras; standups, emails, testing. We want to focus on writing the code.

In the last article, we looked at the qualities of a good PR message and how to write one. Crafting the perfect PR message takes a lot of work. But what if you don't have to do it yourself?

Today, we've observed a boom in generative AI and LLMs (Large Language Models). We have generative AI models like GPT-4, DALL-E, Stable DIffusion, LLaMA, and more. We've also seen tools that use these models to solve problems and automate tasks like never before. If you're reading this, you have probably used ChatGPT at some point in time to do things that would take you hours in seconds.

In this article, we will be exploring how we can take advantage of some of these tools to help us write better PR messages and allow us to focus on what truly matters, the code.

Scenario

To illustrate how we can let AI handle our PR messages, I'm going to be using an open-source project written by a good friend of mine (Alfred) on Microservices; a simple illustration of how to build, deploy, and scale (locally) microservices using Docker and Nginx.

Let's head over to the repo and fork it.

Image of the Repository

It's a system that helps you keep track of popular TV shows. I'm going to be making changes to one of the microservices called "search-service" because it's written in my favorite programming language (Python). "search-service" handles searching for TV shows using a search query.

Here's what the code we will be changing looks like.

We clone our fork to our local computer and create a new branch called "feature/subquery-search" using the following commands.

git clone https://github.com/your-username/tv-shows-microservice

git branch feature/subquery-search

git checkout feature/subquery-search
Enter fullscreen mode Exit fullscreen mode

We're going to be making a PR to enhance the search service. If you take a look at the code, you will observe that it takes in a search parameter, and searches for tv-shows with that parameter using regular expressions. What happens when what you searched doesn't match any of the TV shows?

We'd also like to return some shows that closely match. A simple way to do this is to break down the search query into different queries and search for those instead. For example, if a user searches for "The Walking Nun", our algorithm will also search for "The Walking", "The Nun", "Walking Nun", "The", "Walking", and "Nun".

Here's A look at what the function looks like.

To make things neater, let's create a function called search_for_shows to handle the regular expressions search for us.

Image of the search_for_shows function

Finally, here's what the search endpoint looks like now.

Image of the search endpoint

Once that has done, we commit our changes and push back to GitHub so we can make our PR.

PR messages with GitHub Copilot

One of the tools we can use to help us create our PR message is GitHub Copilot. GitHub Copilot is an AI-powered peer programmer developed by GitHub. It has recently launched a new feature called GitHub Copilot Chat on VS Code To set up GitHub Copilot, you can check this link. After that, you can ask GitHub Copilot to give you a good PR message based on the changelog.

Prompting Copilot chat to write the PR Message

PR messages with CodiumAI

Another tool to structure your PR message is CodiumAI's PR Agent. I recommend CodiumAI's PR Agent for a couple of reasons.

CodiumAI's PR Agent is easy to integrate. You don't need to install CodiumAI on VS Code (though that option is also available).

Image description

You can mention the CodiumAI's PR Agent in the comment section of the Pull Request. it automatically makes the necessary changes to the title and description. To use this feature, you will need to add CodiumAI either as a GitHub App or GitHub Action in your repository to make it work. You can check out this guide on how to get that done.

CodiumAI rewriting PR messages like a cha

CodiumAI works on both sides of the table. It's not just a great tool for writing good PR messages, but it's also a great tool for reviewing the PRs of your teammates. With the CodiumAI command "/review", you get to see an analysis of the branch's changelog, including things like a general summary of the changes, how long it will take you to go through the PR, the type of PR, and suggestions on the PR. So even if your teammates didn't use CodiumAI to structure their PR messages, you can use CodiumAI to review the PRs.

Using the /review command

CodiumAI also provides an "/ask" command which lets you ask questions about the PR and what has changed. Think of this as having ChatGPT inside the PR.

Using the /ask command

You can ask any questions about the code and what has changed. You also get an "/improve" command that shows code suggestions for the PR.

using the /improve command

Here's a link with all the recommendations from CodiumAI You also have the option to just commit the changes directly to the pull request. (Pretty cool right?)

GitHub Copilot VS CodiumAI's PR Agent

In this article, we have discussed two AI tools that can assist us in creating our PR messages. The question now arises as to which one should we use.

GitHub Copilot is an excellent tool for generating code, as it is its primary function. It is a pair programmer AI trained on all open-source code repositories on GitHub, making it extremely powerful for coding tasks. However, its strength in writing effective PR messages may not be as comprehensive or tailored specifically for PR needs.

CodiumAI's PR Agent, on the other hand, specializes in structuring PR messages. It automatically adjusts titles and descriptions based on the content of the PR. Since this AI agent is designed specifically for PRs, it is easier to work with and has more commands that help in other aspects of code collaboration.

Conclusion

In conclusion, AI-powered tools like CodiumAI's PR Agent and GitHub Copilot can help us write better PR messages and save us time. With these tools, we can focus on writing quality code and let the AI handle the tedious tasks of structuring and reviewing PR messages. Consider using one of these AI-powered tools to help you out next time you're creating a PR message.

💖 💪 🙅 🚩
tecnosam
Samuel Abolo

Posted on December 8, 2023

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

Sign up to receive the latest update from our blog.

Related