← Back to blog

n8n Code Review Agent: From PR Webhook to Posted Comment

Build an n8n code review agent step by step: wire a GitHub or GitLab pull-request webhook to an AI Agent that reviews diffs and posts comments.

An n8n code review agent moving a diff through a lens toward a stamped pull request comment.

Checked against the cited sources on .

What You'll Build: An n8n Code Review Agent From PR to Comment

A pull request envelope, a diff scroll and a stamped comment bubble arranged on a workbench.
An illustrative view of the three ingredients an n8n code review agent combines: the trigger, the diff and the comment.

This is an editorial exercise, not a build we ran or verified end to end: a self-contained task you can attempt yourself. The goal is to design an n8n code review agent that watches a pull request or merge request, reads the diff, checks it against your team's written conventions, and posts a structured comment back onto the PR or MR without anyone copying text between tools.

n8n's AI Agent node cannot reason over a diff on its own. Official n8n documentation states that the node requires at least one connected tool sub-node before it can run, so any n8n code review agent design needs to give the agent something to call, whether that is a diff-fetching tool, a conventions document, or both.

Sources: AI Agent | Nodes | n8n Docs

Prerequisites and Inputs You'll Need

A clipboard with tagged tokens for repository, model, conventions, credential and webhook, with two tags being ticked off.
A conceptual checklist of the accounts, credentials and inputs this exercise assumes before you start.

Before wiring anything, line up four things: an n8n instance, cloud or self-hosted, a GitHub or GitLab account with a repository you can safely test against, API credentials scoped to that repository, and an AI provider account whose model you plan to call from the AI Agent node.

On the credentials side, n8n's own documentation recommends a personal access token with the repo scope for most GitHub node operations, while a GitLab credential is documented as needing the broader api scope to unlock the node's full functionality. Because this workflow only needs to read diffs and post comments, that GitLab guidance points to more access than the task strictly requires.

Sources: GitHub credentials | Nodes | n8n Docs, n8n-docs/docs/integrations/builtin/credentials/gitlab.md at main · n8n-io/n8n-docs · GitHub

Building the Workflow: Five Steps From Webhook to Comment

A conveyor of stations showing a diff moving through trigger, fetch, conventions, agent and comment steps.
A conceptual process view of the five stages an n8n code review agent moves a pull request diff through.

The overall shape of an n8n code review workflow is short: a trigger, a diff fetch, a conventions lookup, an agent call, and a comment post. The diagram below lays out that order; the paragraphs after it cover the decisions that matter at each stage.

From pull request to posted review: 1. Trigger; 2. Fetch diff; 3. Load conventions; 4. Run agent; 5. Post comment

GitHub's own node documentation lists pull request operations that include fetching the diff or patch directly, alongside GitHub Trigger events for plain pull request activity, review submissions and review comments. GitLab's trigger similarly exposes a merge-request event, but the documented GitLab app node's operations cover files, issues, releases, repositories and users, with no listed merge-request action for fetching a diff or posting a comment. One documented community build works around that gap by calling the GitLab API through an HTTP Request node instead, the pattern it used for its n8n code review GitLab workflow.

GitHub vs GitLab node support for this workflow
StepGitHub app nodeGitLab app node
Fetch diffDocumented Get Diff / Get Patch operationNo documented merge-request operation; the one documented community build we reviewed used HTTP Request
Post commentDocumented comment-creation operationNo documented merge-request operation; the one documented community build we reviewed used HTTP Request
Trigger eventPull request, review and review-comment eventsMerge request event alongside issues, pipelines and other activity

For team conventions, one documented community build connects a Google Sheet holding a team's coding standards as a tool the AI Agent can query, rather than pasting the rules into the prompt text. We think that tool-based approach is worth the extra setup: it keeps one workflow reusable across repositories with different standards, instead of forking the prompt every time a rule changes.

Once the agent has both the diff and the conventions, the next design choice is output shape. Asking the model for structured output, for example a JSON array of file, line and comment fields, and parsing it with n8n's Structured Output Parser gives the comment-posting step predictable data to map, echoing how one documented community build shaped its GitLab review comments. In a separate community blog post about building an AI code-review automation, developer Harsh Jolapara describes the same kind of automation this way:

Posting back is usually the simplest node call: GitHub's node includes a comment-creation operation, and one documented community build uses it to publish the AI's feedback once the agent finishes; the GitLab equivalent again goes through an HTTP Request node in the one documented community build we reviewed for GitLab. Either way, treat the AI's comment as a draft opinion in the PR, not a merge gate.

Sources: AI Agent | Nodes | n8n Docs, GitHub Trigger | Nodes | n8n Docs, GitHub | Nodes | n8n Docs, GitLab Trigger | Nodes | n8n Docs, n8n-docs/docs/integrations/builtin/app-nodes/n8n-nodes-base.gitlab.md at main · n8n-io/n8n-docs · GitHub, Automate GitHub Code Reviews with n8n’s AI Agent | by Anirban Mukherjee ✍️ | Medium, Can AI Be Your Code Reviewer? Building an Automated Merge Request Reviewer with n8n and LLM | by Rerngrit Frank | Medium

Constraints and Completion Criteria

Two toolboxes comparing GitHub and GitLab node support for fetching diffs and posting review comments.
An illustrative comparison of how much a documented app node covers on each platform for this workflow.

Token scope, rate limits and diff size are the three constraints most likely to bite. Scope credentials minimally: a GitHub PAT with the repo scope, or a GitLab token scoped as narrowly as your platform allows below the broad api scope that n8n's docs describe as the easy default.

Rate limits differ by platform. GitHub's API expects clients to wait until the time given in its rate-limit reset header before retrying, and GitLab specifically throttles comment creation on issues and merge requests to a documented limit on GitLab.com, separate from its general API limits; self-managed or dedicated GitLab instances set their own limits, which the documentation notes without giving a figure. We'd design for backoff and a maximum-retries cap from the start rather than adding it after a workflow trips a limit in production.

Call the exercise complete once a genuinely new pull or merge request triggers the n8n code review agent workflow, the diff and conventions both reach the AI Agent, the agent returns structured output the workflow can parse without manual fixing, and a comment appears on the PR or MR that reflects the diff's actual content.

Sources: GitHub credentials | Nodes | n8n Docs, n8n-docs/docs/integrations/builtin/credentials/gitlab.md at main · n8n-io/n8n-docs · GitHub, Rate limits for the REST API - GitHub Docs, GitLab.com rate limits | GitLab Docs

Reflection, Troubleshooting and a Suggested Solution Sketch

A working n8n code review agent should feel boring in the best sense: it fires quietly on new pull requests and leaves one useful comment, nothing more. Because none of the tutorials behind this exercise document error handling for a failed AI call or a failed comment post, and no source here confirms the exact comment schema either platform's node expects, we'd treat the whole flow as a draft to test on a low-traffic repository before trusting it on anything that matters. Our pragmatic call: skip fully automated posting at first and route the agent's output to a private channel for a week before letting it comment on real pull requests.

Typical failure points worth checking during testing include an oversized diff that the model truncates or mishandles, structured output that almost but not quite matches your parser's schema, and a comment-post call that fails silently after the AI call already succeeded.

If you want to practice the underlying pattern, connecting an AI Agent node to a single tool with conversational memory, before adding a webhook trigger and two external APIs on top, the Your First AI Agent challenge builds exactly that combination in your own n8n environment.

Sources: AI Agent | Nodes | n8n Docs, Automate GitHub Code Reviews with n8n’s AI Agent | by Anirban Mukherjee ✍️ | Medium, Can AI Be Your Code Reviewer? Building an Automated Merge Request Reviewer with n8n and LLM | by Rerngrit Frank | Medium

Put this into practice

Your First AI Agent

Build an AI Agent that looks up Wikipedia to answer your questions.

Beginner

Try a hands-on challenge

For your team

Custom n8n training programs for one team or department, run on your own n8n instance with your own tools and data.

Training for your team

n8n skills assessment

A free quiz of about 20 minutes: 30 questions in 10 skill areas and a level from Beginner to Expert. On AI Adoption Score, another project by the author of this site.

Get your n8n level