ChatGPTSoftwareCode reviewAI score · PendingAI-assisted edit · no obvious prompt-injection riskn8n.io

GitLab MR +0 Triggered ChatGPT Automatic Code Review

GitLab comment → n8n webhook → fetch MR changes → GPT review → post discussion reply

Some experienceStepsWorkflowPrompt
Who
Engineers who want automated code reviews or a second opinion on GitLab Merge Requests
You get
After typing +0 on an MR comment, automatically fetch code changes and have GPT generate a review, posted as a discussion reply on the relevant line
You need
n8n · gitlab

Constraints

Prerequisites: accessible n8n instance; GitLab project Maintainer or Owner role to configure webhooks; GitLab Private Token; OpenAI API key (credential type openAiApi). Default model is gpt-4o-mini, switchable to gpt-4o in the OpenAI Chat Model node. Trigger word +0 can be customized in the Need Review node.

What they did

Author assert published this workflow template on the n8n official template library. The template listens for GitLab note_events webhooks on MR comments, detects +0, automatically fetches MR changes via the GitLab API, filters valid diffs file by file, parses old and new code, sends them to a GPT model for review, and writes the review back as a precisely positioned discussion reply.

How it went

The template is listed on n8n.io with 33,553 total views at time of collection (author_report via n8n-2167-api.json). No specific success rate or ROI data provided.

Worth knowing

Trigger word +0 is customizable in the Need Review node; default model is gpt-4o-mini with gpt-4o available in the OpenAI Chat Model node; both Post Discussions and Get Changes require a GitLab Private Token, and the template hardcodes gitlab.com—self-hosted GitLab instances must replace the domain; diff parsing is sensitive to format edge cases and may return -1 or null for lastOldLine/lastNewLine, causing positioning fallback; this site has not executed the template (reproduction=not_tested).

n8n workflow template

Structure checked · Not run-tested

Use “Import from File” in n8n, or copy the JSON and paste it into the editor. Connect your own accounts, then try test data. The template is inactive by default.

Setup and test checklist

Credentials to connect

  • OpenAI Chat Model node: connect OpenAI API credentials.

Configuration to replace

  • Source template is n8n public workflow #2167 (~14 nodes). Keep inactive after import; verify triggers, expressions and external API endpoints.
  • Sticky-note guidance is informational; replace placeholders with your own accounts, sheet schemas or channel IDs.

Test input and expected output

  • Manually run the main path once in a test workspace and confirm credentialed nodes authenticate without errors.
  • Drive one synthetic/redacted sample through and check output fields and downstream writes before enabling in production.

Template changes

  • Author credential bindings, webhookId and execution data are removed; the workflow is inactive. Nodes, connections and original prompts are preserved. Not run-tested in n8n.
  • No business-logic edits; verify keys, quotas and privacy compliance before use.

Template retrieved: 2026-10-24

Steps

  1. Configure webhook and credentials

    Create a webhook in GitLab project settings with note_events, pointing to the n8n Webhook node URL. Configure OpenAI API credentials (type openAiApi) in n8n. In the Need Review node, confirm the condition checks if comment content equals +0 (modifiable to other keywords).

  2. Fetch and filter changed files

    Once triggered, the Get Changes node calls the GitLab API to retrieve the MR changes list. The Split Out node splits the changes array into individual items. The Skip File Changes node filters out entries where renamed_file=true, deleted_file=true, or diff does not start with @@, keeping only valid code changes.

  3. Parse diff and extract old vs new code

    The Parse Last Diff Line node runs JavaScript to parse the last line of the diff, computing lastOldLine and lastNewLine for later positioning. The Code node splits the diff by line: lines starting with - go to originalCode, lines starting with + go to newCode, and all other lines are kept in both.

  4. LLM review of changes

    The Basic LLM Chain node assembles file path, original code, and new code into a prompt, calling the OpenAI Chat Model (default gpt-4o-mini) to generate a review. The system message instructs the model to act as a senior programming expert, give an accept/reject decision, a 0-100 score, point out issues in concise and stern language, and optionally provide modified content, all in strict Markdown format.

    Execution prompt · Source text。Basic LLM Chain node text parameter (user message template)

    =File path:{{ $('Skip File Changes').item.json.new_path }}
    
    ```Original code
     {{ $json.originalCode }}
    ```
    change to
    ```New code
     {{ $json.newCode }}
    ```
    Please review the code changes in this section:

    Execution prompt · Source text。Basic LLM Chain node messages.messageValues[0].message (system message)

    # Overview:| You are a senior programming expert Bot, responsible for reviewing code changes and providing review recommendations. At the beginning of the suggestion, it is necessary to clearly make a decision to "reject" or "accept" the code change, and rate the change in the format "Change Score: Actual Score", with a score range of 0-100 points. Then, point out the existing problems in concise language and a stern tone. If you feel it is necessary, you can directly provide the modified content. Your review proposal must use rigorous Markdown format.
  5. Post review back to MR discussion

    The Post Discussions node calls the GitLab API via POST with multipart-form-data to create a discussion on the MR. The body is the LLM-generated review text; position parameters include old_path, new_path, start_sha, head_sha, base_sha, and the parsed new_line/old_line to precisely anchor the comment. PRIVATE-TOKEN must be supplied in headerParameters.

Prompt you can copy

Setup guidance · Editorial suggestion。Hand to setup assistant to confirm inputs and permissions before guiding template import and credential replacement

This block is the prompt. Ads are never placed here.

You are setting up an n8n workflow: when a GitLab Merge Request receives a +0 comment, automatically fetch the MR's code changes, have GPT review them, and post the review as a discussion reply on the corresponding code line. First confirm you have: 1) an accessible n8n instance; 2) GitLab project webhook configuration permission; 3) GitLab Private Token; 4) OpenAI API key. Then import the template and replace credentials and URLs.

Replace YOUR_GITLAB_TOKEN, YOUR_OPENAI_KEY, and gitlab.com with actual values before testing

Source

ChatGPT Automatic Code Review in Gitlab MR · assert · n8n.io · 2024-03-07

Comments & feedback

Tried this method? Share results, problems or improvements. Comments appear after moderation. Please avoid sensitive information.

Loading…

    Related