The Code Review Killer: Ditch Manual Checks with this n8n & GPT Automation Guide
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
| Tool | Role in the System |
|---|---|
| n8n | Workflow creation – connects GitHub to OpenAI, manages logic, and formats output. |
| NHost | Managed PostgreSQL database – stores n8n workflow data and credentials (free tier). |
| Render | Hosts the n8n web service, provides a domain URL, and connects to the NHost database. |
| OpenAI | Provides 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
- Create an account on NHost.
- Start a new project and set up a PostgreSQL database.
- Note the generated environment variables (they’ll be needed later).

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

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_quotaerrors. - 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

In n8n, drag the following nodes onto the canvas (right‑hand pane):
- GitHub Trigger – fires on a pull‑request event.
- HTTP Request – fetches the PR diff.
- Code (JS) – builds the prompt for OpenAI.
- OpenAI – generates the review.
GitHub Trigger
- In GitHub, create a Personal Access Token with full repo access.
- In n8n, search for GitHub and add the “on a pull request” trigger node.
- Configure the node with your GitHub credentials and save.
- The node will display a unique Webhook URL – copy this for the next step.

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>.

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.

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.