Use this powerful n8n workflow to automate sophisticated code reviews in GitLab Merge Requests using OpenAI (GPT-4o mini). Filter review triggers and post detailed AI feedback directly on the specific diff lines.
Download this n8n workflow template and start using it instantly.
Maintaining high code quality requires rigorous review, but manual processes can be slow and inconsistent. This specialized n8n workflow solves this by integrating a powerful AI model directly into your GitLab development loop. When a specific trigger comment (like '+0') is left on a Merge Request discussion, this n8n automation takes over. It fetches the latest code changes, processes the file diffs, and sends both the original and new code segments to OpenAI.
The AI, acting as a senior expert, analyzes the changes, assigns a score, and provides a formatted, stern review proposal (accept or reject). Finally, the n8n node posts this detailed review back to GitLab as a discussion thread, precisely pinned to the relevant lines of the code change. This n8n workflow stands as an excellent example of using custom n8n templates to achieve complex, real-time developer tooling.
This automation begins with the configured n8n trigger:
Webhook n8n trigger listens for incoming POST requests from GitLab (typically configured for merge request comments).Need Review n8n node acts as a gatekeeper, checking if the comment body matches the defined trigger word (e.g., +0). If matched, the workflow continues.Get Changes n8n node uses an HTTP request to query the GitLab API for the detailed changes (diffs) within the relevant Merge Request.Split Out n8n node separates the overall response into individual items, one for each modified file change.Skip File Changes n8n node ensures that only files with actual code differences (excluding renamed or deleted files) proceed to analysis.Parse Last Diff Line n8n node uses custom JavaScript to determine the precise line numbers (lastNewLine, lastOldLine) needed by GitLab to anchor the discussion comment correctly.Code n8n node parses the raw Git diff, structuring it into originalCode and newCode payloads suitable for the LLM.Basic LLM Chain utilizes the configured OpenAI Chat Model (GPT-4o mini). It sends the file path and separated code segments, prompting the AI to perform a senior-level code review, providing a score and an Accept/Reject decision.Post Discussions n8n node sends an HTTP POST request back to the GitLab API. It uses the LLM output and the calculated line coordinates to create a new discussion comment, completing the automated review loop.To deploy this powerful n8n workflow, follow these steps:
OpenAI Chat Model n8n node.httpRequest n8n nodes (Get Changes and Post Discussions). Replace the placeholder GitLab URL with your actual instance URL and configure the PRIVATE-TOKEN header using a valid GitLab Access Token (ensure it has merge request write permissions).Webhook n8n trigger node, copy the URL provided (it will be unique to your instance).Need Review n8n node and the sticky notes to customize the trigger word (+0 in this template) and refine the AI's system prompt in the Basic LLM Chain n8n node as necessary. Webhook (n8n trigger): Serves as the starting point, listening for incoming events from GitLab when a discussion note is created or updated.
Need Review (If n8n node): Essential logic gate. Checks the incoming note content to see if it matches the specific review command (+0), ensuring the n8n workflow is only executed when requested.
Get Changes (HTTP Request n8n node): Retrieves the specific diff information for the GitLab Merge Request using the project and MR IDs passed by the initial trigger.
Split Out (n8n node): Transforms the API response to handle each file change individually, enabling sequential processing by the AI.
Parse Last Diff Line & Code (Code n8n nodes): These nodes contain custom JavaScript logic to meticulously parse the complex Git diff format. They extract the exact originalCode and newCode segments and calculate the positional coordinates required for GitLab to place the AI comment correctly.
Basic LLM Chain (n8n node): Defines the large language model prompt, instructing the AI to act as a rigorous code reviewer, demanding an Accept/Reject decision and a score.
OpenAI Chat Model (n8n node): Connects the chain to the GPT-4o mini model using established OpenAI credentials for high-speed, intelligent analysis.
Post Discussions (HTTP Request n8n node): The final action. It constructs a complex API payload using all gathered data (LLM output, file paths, line numbers) to post the automated AI review as an official discussion thread in the GitLab Merge Request.
Deploy a robust n8n workflow that connects an OpenAI Agent (GPT-4) to PostgreSQL data (P&L, Balance Sheets) for real-time, conversational financial analysis. This advanced n8n templates solution streamlines reporting.

Deploy an advanced AI chatbot using this n8n workflow. Connect Google Sheets data via a RAG system to answer schedule questions instantly in Telegram using a custom n8n node.

Run your private AI conversations locally. This n8n workflow connects a chat trigger to your self-hosted Ollama LLMs, providing secure and customizable local automation.

Use this powerful n8n workflow to automate medical or dental appointment scheduling using an AI Agent, Google Calendar, and Google Sheets. A robust n8n template for service providers.









































