The Code Review Killer: Ditch Manual Checks with this n8n & GPT Automation Guide

Published: (December 1, 2025 at 10:07 PM EST)
4 min read
Source: Dev.to

Source: Dev.to

Introduction

Manual code reviews are essential but can be expensive, slow, and inconsistent. While tools like GitHub Copilot’s Code Review feature require a paid subscription (Copilot Pro $10 USD/month or $100 /year; Copilot Pro+ $39 USD/month or $390 /year), you can build a low‑cost, automated AI code‑review assistant that runs for free or near‑free.

Tools

ToolRole in the System
n8nWorkflow creation – connects GitHub to OpenAI, manages logic, and formats output.
NHostManaged PostgreSQL database – stores n8n workflow data and credentials (free tier).
RenderHosts the n8n web service, provides a domain URL, and connects to the NHost database.
OpenAIProvides the LLM that reviews the code.

Why PostgreSQL (NHost) over SQLite?

n8n uses SQLite by default, which is fine for local development but does not handle highly concurrent transactions well and struggles with scalability. A PostgreSQL instance on NHost offers stable, scalable storage while still fitting within a free‑tier personal project.

Database Setup and Hosting

The infrastructure follows the steps described in the article “The Ultimate Guide to Self‑Hosting n8n for Free using Render and Nhost”.

Step 1 – NHost

  1. Create an account on NHost.
  2. Start a new project and set up a PostgreSQL database.
  3. Note the generated environment variables (they’ll be needed later).

NHost Setup

Step 2 – Render

  1. Sign up on Render and create a new Web Service.
  2. Use the Docker image n8nio/n8n:latest.
  3. Add the environment variables from NHost to the Render project settings.
  4. Render will deploy n8n and give you a domain name.

Render Setup

Step 3 – Configure Webhook URL

To let GitHub reach your n8n instance, set the following variables in Render → Web Service → Environment Variables:

WEBHOOK_URL="https://[your-render-domain].onrender.com/"
N8N_HOST="[your-render-domain].onrender.com"
N8N_PROTOCOL="https"

Credentials Required

  • GitHub Access Token – Generate a Personal Access Token with the repo scope (required for reading PR data and posting comments).
  • OpenAI API Key – An active key is needed; new users may have free trial credits, but most will need to spend at least $5 to avoid insufficient_quota errors.
  • Cost Control – The guide uses gpt-5-nano (the cheapest model) to minimize token usage. Any capable model can be swapped in, though the “Mini” series offers a good power‑to‑cost ratio.

Creating the Workflow

Workflow Diagram

In n8n, drag the following nodes onto the canvas (right‑hand pane):

  1. GitHub Trigger – fires on a pull‑request event.
  2. HTTP Request – fetches the PR diff.
  3. Code (JS) – builds the prompt for OpenAI.
  4. OpenAI – generates the review.

GitHub Trigger

  1. In GitHub, create a Personal Access Token with full repo access.
  2. In n8n, search for GitHub and add the “on a pull request” trigger node.
  3. Configure the node with your GitHub credentials and save.
  4. The node will display a unique Webhook URL – copy this for the next step.

GitHub Trigger

Fetching the Code Diff

The trigger node supplies PR details in $json.body.pull_request. Construct the API endpoint to retrieve changed files:

{{ $json.body.pull_request.url }}/files

Add an HTTP Request node that:

  • Calls the above URL.
  • Uses the GitHub Access Token credential for Authorization: Bearer <token>.

Fetching Code Diff

Defining the AI Persona

Create a Code (JS) node to build the prompt sent to OpenAI. Example structure:

const reviewPrompt = `
You are a Senior Software Engineer tasked with reviewing a pull request.
Provide concise, actionable feedback covering:
- Code correctness
- Security concerns
- Performance implications
- Style and best‑practice adherence
- Suggested improvements
`;

return {
  model: "gpt-5-nano",
  messages: [
    { role: "system", content: reviewPrompt },
    { role: "user", content: $json["diff"] } // the diff fetched earlier
  ]
};

Feel free to customize the reviewPrompt to match your team’s standards.

Defining AI Persona

Generating the Review

Add an OpenAI node, select the cheapest capable model (e.g., gpt-5-nano), and map the model and messages fields from the previous JavaScript node. The node will return the AI‑generated review text, which can then be posted back to the PR as a comment using another GitHub node (e.g., “Create Issue Comment”).

Continue wiring the output of the OpenAI node to a GitHub “Create Comment” node, supplying the PR number and the review text.

Back to Blog

Related posts

Read more »