Gemini软件代码评审AI 评分 · 待评分AI 辅助编辑·未发现明显提示词注入风险n8n.io

用 n8n 自动评审 GitLab Merge Request:Gemini AI + JIRA 上下文

输入:GitLab MR 评论触发 → 处理:提取 diff 与可选 JIRA 工单摘要 → 输出:行级 AI 评审意见或 ALL_CLEAR

经验丰富步骤流程提示词
给谁
有 n8n 实例、GitLab 项目管理员权限,并持有 Gemini 与可选 JIRA 凭证的开发团队
你会得到
在 MR 评论中触发后,自动获取变更差异与 JIRA 上下文,由 LLM 生成逻辑/安全/性能问题并回写行级评论;无问题时发布 ALL_CLEAR 备注
你需要
n8n · gitlab · gemini · jira · webhook · http-request

硬约束

前置条件:n8n 实例(自托管或云);GitLab 项目及 Personal Access Token(环境变量 GITLAB_TOKEN);Google Gemini 凭证(googlePalmApi);可选 JIRA Cloud 凭证(jiraSoftwareCloudApi)。费用:Gemini API 按调用计费;JIRA 与 GitLab API 调用受各自速率限制约束。

他们做了什么

作者 jenyok 在 n8n 模板库发布了一个工作流模板。该模板通过 Webhook 监听 GitLab MR 评论事件,当评论匹配触发词时,自动提取 MR 变更差异,可选拉取 JIRA 工单及父工单摘要作为上下文,使用 Google Gemini 2.5 Pro 对代码进行逻辑、安全与性能层面的评审,并将结果以行级评论或 ALL_CLEAR 备注的形式回写到 GitLab MR。工作流使用 Workflow Static Data 存储项目 ID 与 MR ID,以支持跨分支的错误处理与结果回写。

效果如何

作者报告该模板可实现:评论触发后自动获取 MR diff 与 JIRA 上下文,LLM 返回高价值发现或 ALL_CLEAR,结果以行级评论发布;若位置计算失败则降级为 MR 级线程评论;错误时通过 Static Data 定位并通知(author_report)。本站未实测。

值得知道

触发词不一致:模板描述和 sticky notes 声称默认触发词为 `ai-review`,但 workflow.json 中 Need Review 节点实际检查的是 `coro-bot-review`。导入后必须手动核对并修改 IF 节点的触发词。LLM 节点默认使用 models/gemini-2.5-pro,但可替换为其他模型。需要环境变量 GITLAB_TOKEN 而非直接硬编码。JIRA 凭证为可选;无 JIRA 时 LLM 仍执行评审但缺少工单上下文。AI 调用可能产生费用并受地理限制。本站未执行复现(reproduction=not_tested)。

n8n 工作流模板

结构已检查 · 未实际运行

下载后在 n8n 选择“Import from File”,或复制 JSON 后粘贴到编辑器。先配置自己的账号,再用测试数据运行;模板默认未启用。

配置与测试清单

需要绑定的凭证

  • Google Gemini Chat Model 节点:绑定Google Gemini/PaLM API 凭证。
  • Get JIRA issue 节点:绑定jiraSoftwareCloudApi 凭证。
  • Get JIRA Parent Issue 节点:绑定jiraSoftwareCloudApi 凭证。

需要替换的配置

  • 源模板来自 n8n 公开库 #7924(约 41 个节点)。导入后先保持未启用,核对触发器、表达式与外部 API 端点。
  • Sticky Note 中的说明仅供参考;按自己的账号、表结构或频道 ID 替换占位配置。

测试输入与预期结果

  • 在测试环境手动执行一次主路径,确认每个需凭证的节点已连接且无鉴权错误。
  • 用一条合成/脱敏样例数据跑通,核对输出字段与下游写入目标,再考虑生产启用。

模板处理说明

  • 已移除原作者凭证绑定、webhookId 与执行数据,工作流设为未启用;节点、连线与原文提示词保持原样。未在 n8n 中实际运行。
  • 未改业务逻辑;运行前请自行核对密钥、配额与隐私合规。

模板获取日期: 2026-10-24

步骤

  1. 导入模板并配置触发器

    从 n8n 模板库导入 workflow JSON。打开 Webhook 节点,将路径占位符 REPLACE_WITH_UNIQUE_PATH 替换为自定义路径。在 GitLab 项目设置中配置 Webhook,将 MR 评论事件发送至该 URL。在 Gemini(或其他 LLM)节点选择凭证,可选在 JIRA 节点配置凭证。激活工作流。

    搭建指导 · 本站建议版本。搭建助手启动词;用于确认前置条件与权限

    请协助我完成以下 n8n 模板搭建:
    1. 导入模板 JSON(来源:https://n8n.io/workflows/7924/)
    2. 配置 Webhook 节点:将 REPLACE_WITH_UNIQUE_PATH 替换为唯一路径
    3. 在 GitLab 项目 → Settings → Webhooks 中添加 Webhook URL,选择 Merge request events 或 Note events
    4. 配置凭证:Gemini 节点选择 googlePalmApi 凭证;JIRA 节点可选配置 jiraSoftwareCloudApi
    5. 设置环境变量 GITLAB_TOKEN
    6. 激活工作流后,在 MR 中评论触发词测试
    
    请确认以上每一步的输入和权限是否已就绪。
  2. 触发监听与数据准备

    当 GitLab MR 收到包含触发词的评论时,Webhook 节点捕获事件。工作流提取项目 ID 与 MR IID,存入 Workflow Static Data 以便后续节点和错误处理复用。同时向 MR 发送「AI review started」状态消息。随后通过 GitLab API 获取 MR changes,解析 diff 为 original/new 代码块;若 MR 描述含 JIRA 工单号,则拉取工单摘要,如是子任务再拉取父工单摘要,合并为上下文。

  3. LLM 代码评审

    将解析后的 diff 块与可选 JIRA 上下文送入 Basic LLM Chain。Gemini 2.5 Pro 按系统指令只关注逻辑正确性、安全与性能问题,忽略风格与文件名等。发现问题时以 🤖 **AI Review:** 为前缀输出可执行建议;无问题时返回 ALL_CLEAR。

    运行提示词 · 来源原文。Basic LLM Chain 节点的 messages.messageValues[0].message 字段(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.

    运行提示词 · 来源原文。Basic LLM Chain 节点的 text 字段(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:

    运行提示词 · 来源原文。使用前确认粘贴位置、输入变量及输出格式。

    ### ⭐️ 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.

    运行提示词 · 来源原文。使用前确认粘贴位置、输入变量及输出格式。

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

    运行提示词 · 来源原文。使用前确认粘贴位置、输入变量及输出格式。

    ### 🟣 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`.

    运行提示词 · 来源原文。使用前确认粘贴位置、输入变量及输出格式。

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

    运行提示词 · 来源原文。使用前确认粘贴位置、输入变量及输出格式。

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

    运行提示词 · 来源原文。使用前确认粘贴位置、输入变量及输出格式。

    ### 🟡 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. 结果回写与错误兜底

    LLM 输出经聚合后,由 Process Comments 节点过滤有效评论。若存在 issues,转换为 GitLab discussion payload 并尝试在行级位置发布;若位置计算失败,降级为 MR 级线程评论。若全部为 ALL_CLEAR,则发布「No significant issues were found. LGTM!」备注。Error Trigger 路径通过 Static Data 中存储的项目 ID 与 MR ID,向对应 MR 发送错误通知,最后清理 Static Data。

  5. 自定义与调优

    可在 IF 节点(Need Review)修改触发词;在 Basic LLM Chain 调整 system message 以关注风格或文档;在 Skip File Changes 或 Prepare Code Changes 节点增加文件类型过滤;也可集成 Slack/Email 节点发送完成通知。

可复制提示词

搭建指导 · 本站建议版本。交给搭建助手,先确认输入和权限

这一段是提示词,页面不会在这里插入广告。

请协助我完成以下 n8n 模板搭建:
1. 导入模板 JSON(来源:https://n8n.io/workflows/7924/)
2. 配置 Webhook 节点:将 REPLACE_WITH_UNIQUE_PATH 替换为唯一路径
3. 在 GitLab 项目 → Settings → Webhooks 中添加 Webhook URL,选择 Merge request events 或 Note events
4. 配置凭证:Gemini 节点选择 googlePalmApi 凭证;JIRA 节点可选配置 jiraSoftwareCloudApi
5. 设置环境变量 GITLAB_TOKEN
6. 激活工作流后,在 MR 中评论触发词测试

请确认以上每一步的输入和权限是否已就绪。

搭建前请确认:GitLab PAT 已设为 GITLAB_TOKEN;Webhook 路径已替换;Gemini 凭证已配置;触发词与模板默认一致(注意模板描述写 ai-review,但导入后需检查 Need Review 节点的实际值)。

来源

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

留言与反馈

试过这个方法吗?分享效果、遇到的问题或改进建议。留言审核后公开,请勿填写敏感信息。

正在加载…

    相关用例