View all articles
n8ncode reviewOllamaautomationDevOps

Automate Code Reviews with AI: n8n + Ollama Workflow Tutorial

JG
Jacobo González Jaspe
|

Reviewed:

Abstract illustration: ribbons of amber and white light weaving in a gentle curve. Models
Illustration generated with AI on our own machine.

Updated 4 October 2026. This post is from March 2026 and names GPT-4, Qwen 2.5 as current. The method and the advice still hold; today you would run it with:

  • Qwen 3.6: Use the medium-sized version for better instruction following during the diff analysis step.
  • Gemma 4: Replace the existing model with this version to improve the accuracy of the review formatting.
  • DeepSeek V4: Use a small quantised version if you need faster processing of large pull request diffs.

Every pull request needs a review, but bandwidth is often limited. This tutorial shows you how to build a code review pipeline using n8n and a local LLM via Ollama. It is completely self-hosted with no API costs and no data leaving your network.

n8n AI workflow automation

What This Workflow Does

  1. Receives a webhook when a PR is opened on GitHub/GitLab
  2. Fetches the diff (code changes) from the PR
  3. Sends the diff to Ollama (local LLM) for analysis
  4. Formats the review into a structured report
  5. Posts the review to Discord (or Slack, email: your choice)
  6. Responds to the webhook confirming the review was posted

Total: 6 nodes, ~5 minutes to set up, zero recurring cost.

Architecture

text
GitHub PR Webhook → n8n → Fetch Diff → Ollama (local) → Format Review → Discord

The entire pipeline runs locally. Your code never touches a third-party API. This is critical for companies handling proprietary code or operating under GDPR constraints.

Prerequisites

  • n8n installed (self-hosted or cloud)
  • Ollama running with a code-capable model: ollama pull qwen2.5-coder:7b
  • GitHub/GitLab webhook access to your repository
  • Discord webhook URL (or Slack incoming webhook)

Step-by-Step Setup

1. Configure the Webhook Trigger

Create a new n8n workflow and add a Webhook node:

  • HTTP Method: POST
  • Path: /pr-review
  • This generates a URL like https://your-n8n.com/webhook/pr-review

Register this URL in your GitHub repo: Settings → Webhooks → Add webhook → Payload URL → Select “Pull requests” events.

2. Fetch the Diff

Add a Code node to extract the diff URL from the webhook payload:

JavaScript
const prUrl = $input.first().json.pull_request.diff_url;
const title = $input.first().json.pull_request.title;
const author = $input.first().json.pull_request.user.login;
return [{ json: { prUrl, title, author, diffUrl: prUrl } }];

3. Send to Ollama for AI Review

Add an HTTP Request node:

  • Method: POST
  • URL: http://localhost:11434/api/generate
  • Body (JSON):
JSON
{
  "model": "qwen2.5-coder:7b",
  "prompt": "Review this code diff. Focus on: bugs, security issues, performance problems, and code style. Be specific and reference line numbers.\n\nDiff:\n{{ $json.diff }}",
  "stream": false
}

This sends the diff to your local Ollama instance. The model runs on your hardware, no tokens billed, no data uploaded.

4. Format the Review

Add another Code node to structure the output:

JavaScript
const review = $input.first().json.response;
const title = $('Fetch Diff').first().json.title;
const author = $('Fetch Diff').first().json.author;

return [{
  json: {
    content: `**AI Code Review** 🤖\n**PR:** ${title}\n**Author:** ${author}\n\n${review}\n\n_Powered by Vorlux AI + Ollama (local inference)_`
  }
}];

5. Post to Discord

Add an HTTP Request node:

  • Method: POST
  • URL: Your Discord webhook URL
  • Body: { "content": "{{ $json.content }}" }

6. Respond to Webhook

Add a Respond to Webhook node returning { "status": "reviewed" }.

Download the Workflow

This exact workflow is available as a ready-to-import JSON file:

Download ai_code_review.json →

Import it in n8n: Settings → Import Workflow → Upload File.

Why Local AI for Code Review?

FactorCloud API (GPT-4)Local (Ollama + Qwen)
Cost~$0.03-0.10 per reviewEUR 0
PrivacyCode sent to OpenAI serversCode stays on your machine
Speed2-5 seconds (network)1-3 seconds (local)
GDPRRequires DPA with OpenAIFully compliant (local)
AvailabilityDepends on API uptimeAlways available
flowchart LR
    GH["GitHub PR"] --> WH["n8n Webhook"]
    WH --> DIFF["Fetch Diff"]
    DIFF --> AI["Ollama Review"]
    AI --> FMT["Format Output"]
    FMT --> DC["Discord Alert"]
    
    style GH fill:#1E293B,color:#FAFAFA
    style AI fill:#059669,color:#FAFAFA
    style DC fill:#F5A623,color:#0B1628
Diagram

Choosing the Right Model for Code Review

Not all models are equal for code review tasks. Based on our testing across hundreds of PRs:

ModelStrengthsBest ForMemory
Qwen 2.5 Coder 7BInstruction-following, multi-languageGeneral code review~4.5GB
DeepSeek R1 14BChain-of-thought reasoningComplex logic bugs~10GB
Llama 3.3 70BDeep analysis, architectural feedbackArchitecture reviews~40GB
Phi-4 14BFast inference, concise outputQuick PR checks~9GB

For most teams, Qwen 2.5 Coder 7B provides the best balance of quality and speed. If your Mac has 32GB+ memory, consider running DeepSeek R1 14B for its superior reasoning on complex diffs.

Next Steps

  • Replace Discord with Slack or email notification
  • Add a GitHub comment node to post the review directly on the PR
  • Use structured outputs (Ollama JSON schema) for machine-parseable reviews
  • Chain with a test runner workflow for full CI/CD integration
  • Explore n8n’s Model Context Protocol (MCP) support for connecting agents to external tools

Work with us

We size the model and the machine by measuring, not by guessing. If you want to see your own task running on real hardware, book a 15-minute call or see how we work in consulting.

Diagram
Share: LinkedIn X
Veredicto semanal

Get new guides before anyone else

Subscribe and we tell you when new guides, templates and workflows go up. One email a week, no spam.

Already published: 69 guides and 25 templates. All free, no signup.

Bonus: the local-AI starter pack PDF when you subscribe
Once a week No spam Unsubscribe anytime

See what you get

The EU AI Act now applies: a checklist you can complete

Tell us what you want to run

Tell us what you want to run and on what budget. We will tell you which hardware you need, which model fits, and what to expect from it, before you spend anything.

First call free, 15 min Local-first: your data stays on your network Open tools and guides

69 free guides · 17 compliance templates