How to set up automatic AI Reviews in your GitHub Pull Requests with CodeRabbit


How to set up automatic AI Reviews in your GitHub Pull Requests with CodeRabbit

CodeRabbit is an innovative, AI-driven platform that delivers context-aware reviews, improving code quality, reducing the time and effort required for thorough manual code reviews, and enabling teams to ship software faster. It’s quick and easy to set up, and provides several pricing options, depending on your needs.

Setting up your CodeRabbit account

First, create an account or log in using GitHub. If you’re a member of an organization, you’ll have some options regarding which ones you’d like to use CodeRabbit with. If you’re not using it with any, just like me, just proceed without granting/requesting any access. Next, you’ll see a list of organizations CodeRabbit has access to, so select the one you want and click Continue.

You’ll then have the option to choose whether to grant access to all repositories or only to specific ones. In this case, since we’re only implementing it in a single repository, we’ll choose only Skynet, which was created for this purpose.

After this step, you’ll be redirected to the dashboard, which means you are ready to get some insights on your pull requests!

Analyzing CodeRabbit suggestions

Now that we are ready to go, let’s start by creating a simple pull request and investigating how CodeRabbit handles it. Our starting code base is the basic Hello World example from .NET, and we’ll build on top of that. Let’s start by trying to add some random garbage code, as well as changing the printed text.

Once we push the new code and create a pull request, CodeRabbit will automatically hop in and let us know that it’s working on it. This comment will get updated once CodeRabbit finishes analyzing it.

After a while, we’ll get the suggestions, along with a description of the changes in this pull request. We even got a poem for this change, how very polite!

Now that we know what this pull request is about, let’s analyze the actual changes.

To begin with, it detected our terrible for block, stating that it’s both unnecessary, and most interesting, it also complained about the name of the variable, showing that it also tries to enforce clean code principles.

We can accept its suggestion right away, but what if we would like to make small adjustments to it? Apparently, we can just ask it. In this case, I asked CodeRabbit to change the value of the counter to 11. It did reply to me and it did update the suggestion inside the first comment, but it did not update the commitable suggestion. I tried commenting again, suggesting CodeRabbit to create a new commitable suggestion instead, but then I got ghosted.

Anyway, let’s apply his suggestion and proceed with the next comment.

In its next comment, it warns us about the hardcoded “10” in our WriteLine statement, plus it managed to catch the possible relation between the counter and the value we’re printing on screen, nice! However, we can’t use the commitable suggestion anymore, since we have applied the previous suggestion that renamed the counter to “counter”. I tried asking the AI to review this comment, but it ignored me (again).

Let’s try another approach. With CodeRabbit, there are a lot of ways you can interact with it, besides replying to its comments. So let’s try adding a new comment in the PR, tag CodeRabbit and see what we get

So it analyzed the solution for us and gave us 3 different options to handle it, which you can choose by clicking on the check box. For example, by clicking on the first option, “Create PR with these edits”, we got a new PR targeting this branch we’re working on. Depending on the size of the suggested changes, that can be handy if you want to keep your scope smaller.

After merging the new PR, CodeRabbit will run another analysis, and if it is happy with it, you’ll get this approval and you’re all ready to merge! If you’d like to take a look at the repository and the pull request, you can find them here.