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

Automate GitLab MR Code Review with n8n: Gemini AI + JIRA Context

Input: GitLab MR comment trigger → Process: extract diff and optional JIRA ticket summary → Output: line-level AI review comments or ALL_CLEAR

ExperiencedStepsWorkflowPrompt
Who
Development teams with an n8n instance, GitLab project admin access, and Gemini (plus optional JIRA) credentials
You get
On MR comment trigger, auto-fetch changes and JIRA context, have an LLM review for logic/security/performance issues, and post line-level comments back; post ALL_CLEAR if nothing found
You need
n8n · gitlab · gemini · jira · webhook · http-request

Constraints

Prerequisites: n8n instance (self-hosted or cloud); GitLab project and Personal Access Token (environment variable GITLAB_TOKEN); Google Gemini credentials (googlePalmApi); optional JIRA Cloud credentials (jiraSoftwareCloudApi). Costs: Gemini API usage billed per call; GitLab and JIRA API calls subject to respective rate limits.

What they did

Author jenyok published a workflow template in the n8n template library. The template listens for GitLab MR comment events via Webhook, and when the comment matches a trigger phrase, it automatically extracts the MR diff, optionally fetches JIRA issue and parent issue summaries for context, uses Google Gemini 2.5 Pro to review the code for logic, security, and performance issues, and posts the results back to the GitLab MR as line-level comments or an ALL_CLEAR note. The workflow uses Workflow Static Data to store the project ID and MR ID, enabling cross-branch error handling and result posting.

How it went

The author reports that the template can: capture comment triggers, fetch MR diffs and optional JIRA context, have an LLM return high-value findings or ALL_CLEAR, post line-level comments; fall back to MR-level thread comments if position calculation fails; and use stored Static Data to locate and notify on errors (author_report). This site has not tested it.

Worth knowing

Trigger phrase mismatch: the template description and sticky notes claim the default trigger is `ai-review`, but the workflow.json Need Review node actually checks for `coro-bot-review`. You must manually verify and update the IF node trigger phrase after import. The LLM node defaults to models/gemini-2.5-pro but can be swapped. GITLAB_TOKEN is required as an environment variable, not hardcoded. JIRA credentials are optional; the LLM still reviews without JIRA context. AI calls may incur costs and be geo-restricted. This site has not performed reproduction (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

  • Google Gemini Chat Model node: connect Google Gemini/PaLM API credentials.
  • Get JIRA issue node: connect jiraSoftwareCloudApi credentials.
  • Get JIRA Parent Issue node: connect jiraSoftwareCloudApi credentials.

Configuration to replace

  • Source template is n8n public workflow #7924 (~41 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. Import template and configure trigger

    Import the workflow JSON from the n8n template library. Open the Webhook node and replace the REPLACE_WITH_UNIQUE_PATH placeholder with a custom path. In your GitLab project settings, configure a webhook to send MR comment events to that URL. Select your LLM credentials in the Gemini (or other LLM) node, and optionally add JIRA credentials. Activate the workflow.

    Setup guidance · Editorial suggestion。Setup assistant starter; confirm prerequisites and permissions

    Please help me set up this n8n template:
    1. Import the template JSON (source: https://n8n.io/workflows/7924/)
    2. Configure the Webhook node: replace REPLACE_WITH_UNIQUE_PATH with a unique path
    3. In GitLab project → Settings → Webhooks, add the Webhook URL and select Merge request events or Note events
    4. Configure credentials: select googlePalmApi for the Gemini node; optionally configure jiraSoftwareCloudApi for JIRA nodes
    5. Set the GITLAB_TOKEN environment variable
    6. Activate the workflow, then test by commenting the trigger phrase on an MR
    
    Please confirm each step's inputs and permissions are ready.
  2. Trigger listening and data preparation

    When a GitLab MR receives a comment containing the trigger phrase, the Webhook node captures the event. The workflow extracts the project ID and MR IID, storing them in Workflow Static Data for reuse by downstream nodes and error handling. It also posts an "AI review started" status message to the MR. Then it fetches MR changes via the GitLab API, parses the diff into original/new code blocks; if the MR description contains a JIRA issue key, it fetches the issue summary, and for subtasks also fetches the parent issue summary, merging both into context.

  3. LLM code review

    The parsed diff blocks and optional JIRA context are fed into the Basic LLM Chain. Gemini 2.5 Pro follows system instructions to focus only on logic correctness, security, and performance issues, ignoring style and filenames. When issues are found, it outputs actionable suggestions prefixed with 🤖 **AI Review:**; when none are found, it returns ALL_CLEAR.

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

    You are an automated code review bot. Your primary goal is to identify high-value issues in code.
    
    **Instructions:**
    
    1. **Analysis Focus:** Concentrate only on business logic, correctness, security, and performance. Ignore style, naming, filenames, version bumps, and non-source files. Assume placeholders for yml files will be filled with correct values.
    2. **Output for Issues:** When you find an issue, begin your response with the prefix `🤖 **AI Review:** `. Follow it with a concise, actionable explanation. Prefer one-liners that are immediately actionable - what or where or why and how to fix.
    3. **Output for No Issues:** If your analysis finds **zero** issues worth reporting, your **ENTIRE** response must be the single keyword: `ALL_CLEAR`. Do not add any other text or explanation.
    4. ** Findings to ignore in yaml files:**
        - Ignore if a value for vaultSecretPath in a values file or a yaml contains a double slash (//)
        - Ignore errors where tag appears to be very or too specific
    
    **Important Rules:**
    
    * NEVER write praise, summaries, or conversational phrases like "I have no findings."
    * If you find issues, start every comment with the `🤖 **AI Review:** ` prefix.
    * If you find no issues, don't output anything.

    Execution prompt · Source text。Basic LLM Chain node text field (User Message / Prompt)

    =First, consider the context from the associated JIRA ticket:
    ------------
    {{ $json.jiraParentContext || $json.jiraContext || 'No JIRA context was provided.' }}
    ------------
    
    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。Confirm the destination, input variables and output format before use.

    ### ⭐️ Try It Out!
    
    Welcome! This template adds AI-powered code reviews to your GitLab Merge Requests. Simply comment **`ai-review`** on any MR and watch the workflow:
    
    - Captures the comment event.
    - Fetches diff & optional JIRA context.
    - Asks an LLM for insights.
    - Posts inline comments or an 'all clear' note.
    
    Perfect for catching logic, security and performance issues fast.

    Execution prompt · Source text。Confirm the destination, input variables and output format before use.

    ### 🟢 Step 1: Listen & Capture
    
    A Webhook node listens for merge request note events. When the comment text matches your trigger (default: `ai-review`), it:
    
    - Extracts the Project & MR IDs and stores them in a **Static Context** (see below) so later nodes always know where to post results.
    - Posts a short "AI review started" message back to the MR to let reviewers know the bot is working.

    Execution prompt · Source text。Confirm the destination, input variables and output format before use.

    ### 🟣 Step 2: Prepare & Review
    
    The workflow fetches the merge request changes via the GitLab API and parses the diff into original vs new code blocks.
    
    If the MR description contains a Jira key, the workflow fetches the issue summary and, if it's a subtask, also fetches the parent ticket for extra context. Both summaries are combined into the prompt.
    
    An LLM (Gemini by default) is prompted to find critical issues only—logic bugs, security flaws and performance problems—and to return comments with file and line numbers. If no issues exist, the model returns `ALL_CLEAR`.

    Execution prompt · Source text。Confirm the destination, input variables and output format before use.

    ### 🟠 Step 3: Post & Fallback
    
    Review comments are converted into GitLab discussion payloads and posted back to the MR at the correct file and line positions.
    
    If a comment’s position is not calculated properly, the workflow falls back to posting a comment as a thread at the MR level so nothing is lost.

    Execution prompt · Source text。Confirm the destination, input variables and output format before use.

    ### 🔵 Static Context & Error Handling
    
    Workflow Static Data is used to store persistent values—like the project ID and the MR ID so that they will be available across branches.
    
    This is critical for the Error Trigger: if something fails, the error path can still post to the correct MR using these stored IDs. Without static context, error comments wouldn’t know where to go.

    Execution prompt · Source text。Confirm the destination, input variables and output format before use.

    ### 🟡 Need Help & Customise
    
    - Change the trigger word in the **IF** node to match your own.
    - Swap in your preferred LLM or adjust the prompt to suit your guidelines.
    - Filter by file type or exclude certain directories in the parsing logic.
  4. Post results and error fallback

    After LLM outputs are aggregated, the Process Comments node filters for valid review comments. If issues exist, they are converted to GitLab discussion payloads and posted at line-level positions; if position calculation fails, the workflow falls back to posting as an MR-level thread. If all outputs are ALL_CLEAR, a "No significant issues were found. LGTM!" note is posted. The Error Trigger path uses the project ID and MR ID stored in Static Data to send an error notification to the correct MR, then cleans up Static Data.

  5. Customize and tune

    You can change the trigger phrase in the IF node (Need Review), adjust the system message in the Basic LLM Chain to focus on style or documentation, add file-type filters in the Skip File Changes or Prepare Code Changes nodes, or integrate Slack/Email nodes to send completion notifications.

Prompt you can copy

Setup guidance · Editorial suggestion。Setup assistant starter; confirm prerequisites and permissions

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

Please help me set up this n8n template:
1. Import the template JSON (source: https://n8n.io/workflows/7924/)
2. Configure the Webhook node: replace REPLACE_WITH_UNIQUE_PATH with a unique path
3. In GitLab project → Settings → Webhooks, add the Webhook URL and select Merge request events or Note events
4. Configure credentials: select googlePalmApi for the Gemini node; optionally configure jiraSoftwareCloudApi for JIRA nodes
5. Set the GITLAB_TOKEN environment variable
6. Activate the workflow, then test by commenting the trigger phrase on an MR

Please confirm each step's inputs and permissions are ready.

Before setup, confirm: GitLab PAT is set as GITLAB_TOKEN; Webhook path is replaced; Gemini credentials are configured; trigger phrase matches template default (note: template description says ai-review, but check the Need Review node value after import).

Source

Automate code reviews for GitLab MRs with Gemini AI and JIRA context · jenyok · n8n.io · 2025-08-26

Comments & feedback

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

Loading…

    Related