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.

What This Workflow Does
- Receives a webhook when a PR is opened on GitHub/GitLab
- Fetches the diff (code changes) from the PR
- Sends the diff to Ollama (local LLM) for analysis
- Formats the review into a structured report
- Posts the review to Discord (or Slack, email: your choice)
- Responds to the webhook confirming the review was posted
Total: 6 nodes, ~5 minutes to set up, zero recurring cost.
Architecture
GitHub PR Webhook → n8n → Fetch Diff → Ollama (local) → Format Review → DiscordThe 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:
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):
{
"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:
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?
| Factor | Cloud API (GPT-4) | Local (Ollama + Qwen) |
|---|---|---|
| Cost | ~$0.03-0.10 per review | EUR 0 |
| Privacy | Code sent to OpenAI servers | Code stays on your machine |
| Speed | 2-5 seconds (network) | 1-3 seconds (local) |
| GDPR | Requires DPA with OpenAI | Fully compliant (local) |
| Availability | Depends on API uptime | Always 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:#0B1628Choosing the Right Model for Code Review
Not all models are equal for code review tasks. Based on our testing across hundreds of PRs:
| Model | Strengths | Best For | Memory |
|---|---|---|---|
| Qwen 2.5 Coder 7B | Instruction-following, multi-language | General code review | ~4.5GB |
| DeepSeek R1 14B | Chain-of-thought reasoning | Complex logic bugs | ~10GB |
| Llama 3.3 70B | Deep analysis, architectural feedback | Architecture reviews | ~40GB |
| Phi-4 14B | Fast inference, concise output | Quick 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.
Related reading
- Google Gemma 3: The First Multimodal Open Model That Fits on a Mac Mini
- Google Gemma 4: The Open Model Family That Changed Our Entire Stack
- Build a Local RAG Pipeline with n8n and Ollama: Query Your Company Documents with AI
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
Related resources
- 230 Workflows library: browse and download all workflows
- AI Models catalog: find the best model for code review
- Software stack: tools we use and recommend
- Contact us: need help setting this up?
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.