SabaKore

Home / Articles / AI guides

Building AI Code Review into CI

The design for building a mechanism that has AI automatically check code changes into your CI, and where to draw the line so it doesn't replace human review.

Ren, a junior infrastructure engineer

Ren

I want to build something where an AI automatically reviews code every time a change comes in!
Procura, a cloud AI robot who explains

Procura

You can. You build it by adding a call to an AI to your CI (the mechanism that runs automatically every time code changes), handing it the change and having it point out anything of concern.

The VPS's role

  • Set up an endpoint that receives the change from CI, passes it to the AI and compiles the result
  • Build a mechanism that returns the result as comments on the change
  • It doesn't need to run all the time; it only needs to run when there's a change
Ren, a junior infrastructure engineer

Ren

If there's an AI review, can I skip having people review?
Procura, a cloud AI robot who explains

Procura

Please don't misunderstand this. AI easily notices surface problems (quirks in how the code is written, common mistakes), but it doesn't understand context such as why this change is needed for the business. It can't replace human review.

Where to draw the line so it works well

AI review works well when you position it as an aid that reduces the effort of human review. The division of roles is that the AI handles the fine-grained comments while people concentrate on whether the design and intent are sound. Don't swallow the AI's comments whole and mechanically fix things; keep the premise that people make the final decision.

  • Treat the AI's comments as 'suggestions' and don't apply them automatically
  • The more important the change, the less you should skip review by a person
  • Check that the code you hand to the AI doesn't include information that must not leave your control
Procura, a cloud AI robot who explains

Procura

Having checks run automatically is reassuring in itself. But if you feel completely safe and reduce the human eyes on it, no one will look at the parts the AI missed. Think of it only as a double check.
Ren, a junior infrastructure engineer

Ren

What should I do if the AI's comments are often off the mark?
Procura, a cloud AI robot who explains

Procura

If there are many off-target comments, the information you're handing over may be insufficient. Passing the project's conventions and background along with the changes often changes how accurate the comments are. If it still doesn't improve, review the settings that narrow down what is commented on.

Narrowing down what gets commented on

If you hand the AI the entire changed code every time, it not only drives up costs but also increases loosely related comments, which raises the burden on the reader. You can balance the quantity and relevance of comments with measures such as passing only the changed parts and their surroundings, or narrowing down the types of files targeted. Start with a narrow scope and widen the target as needed.

  • Pass only the changed parts and their surroundings to reduce unrelated comments
  • Decide in advance which kinds of files are targeted (only code, excluding config files, and so on)
  • If there are too many comments, narrow it down so that only high-importance ones are shown
Ren, a junior infrastructure engineer

Ren

So the AI helps you notice things, and people make the final decision. Make the roles clear.

This article is translated from the Japanese original. If the two differ, the Japanese version is the one we keep up to date.