Automated AI Code Reviews for GitLab with n8n

Most teams want every merge request to receive a quick, thoughtful review, but human reviewers are often busy or unavailable when code is submitted. By connecting an open-source tool called n8n to an inexpensive large language model, we can trigger an automated code review the moment a GitLab MR opens and post the feedback as a comment. The entire setup can live on your own server, costs only a few cents in tokens (depending on the model used), and is easy to customize.

A short tour of n8n for beginners

If you are new to n8n, think of it as a visual If-This-Then-That on steroids:

  • Drag-and-drop workflow builder. Each node does one job—receive a webhook, call an API, run JavaScript, send an email, and so on.
  • Self-host or cloud. 'docker-compose up -d' and you get unlimited users, unlimited workflows, and full control.
  • JavaScript everywhere. Function nodes let you write JS right in the UI. If you can write and use console.log, you can extend n8n.
  • 500+ integrations. GitLab, GitHub, Slack, AWS, Postgres, you name it.

A workflow starts with a trigger and flows through nodes that enrich or transform data. n8n passes a JSON payload from one node to the next, so you rarely need glue code.

The plan: connect n8n with an AI model

Recent versions of n8n ship with LangChain nodes, which act as thin wrappers around popular LLMs (OpenAI, Anthropic, Ollama, etc.). That means you can:

  1. Drop a LangChain LLM Chat node into any workflow.
  2. Feed it plain text, JSON, or even your own prompt template.
  3. Get the model’s reply back as JSON—ready for the next step.

Because you pay only for tokens, the cost scales with real usage. A typical MR diff (about 200 lines) might burn five-thousand input tokens and one-thousand output tokens on Claude 3-Haiku—roughly 0.8¢. That is pocket change compared to a full-time reviewer.

Why roll your own instead of buying a SaaS code-review bot?

 DIY with n8n + LLMProprietary AI code-review SaaS
CostPay only for tokens you useMonthly seat fee plus usage
PrivacyYou send code only to the LLMDiff is stored on vendor’s cloud
ControlTune prompts, filters, branching logicFeature set is fixed
Integrations500+ n8n nodes out of the boxLimited to code review

If you already self-host GitLab—or you just hate vendor lock-in—rolling your own is the obvious choice.

Building the workflow: node by node

Below is the exact set of n8n nodes I used. You can reproduce it by adding these nodes in order and wiring the main output of each to the next.

#NodeRole in the workflow
1GitLab TriggerFires on every merge_requests event in the repo.
2HTTP Request – “Get diff”Calls GitLab’s /changes endpoint to fetch the full patch for that MR.
3If – “Has changes & MR is open”Skips the run if the MR is closed or the diff is empty.
4If – “Author is not me” (optional)Prevents the bot from reviewing your own WIP branches.
5LangChain AgentSends the diff to an LLM with an instruction like “List potential issues in plain language.”
6HTTP Request – “Post comment”Uses POST /notes to drop the model’s feedback into the MR thread.
7Slack (optional)Notifies a channel that the bot posted a review or skipped one.

With those seven nodes you have a fully automated reviewer that lives inside GitLab.

Image

With seven nodes and a few environment variables you can turn n8n into a tireless, polite reviewer that never sleeps and costs less than two bucks a month. The bot lives where your developers already work—right in the GitLab merge request—and you keep full control over prompts, filters, and data. It is more private than any SaaS bot, cheaper than hiring interns, and easier to tweak than writing a custom microservice.

Here’s a test merge request I opened in GitLab that intentionally adds risky code.

Image

Moments later, the AI reviewer left this comment flagging the issues and suggesting fixes.

Image

Give it a try, swap in your own prompts, and let me know what you automate next. Happy coding—and happy reviewing!

About the Author

Goran Nikolovski is a web and AI developer with over 10 years of expertise in PHP, Drupal, Python, JavaScript, React, and React Native. He founded this website and enjoys sharing his knowledge.

AI Assistant