n8n工作文档AI 评分 · 待评分AI 辅助编辑·未发现明显提示词注入风险n8n.io

用 n8n 并行 AI 审阅 GitLab Merge Request

GitLab 讨论评论触发 → 获取 MR 变更 → 三维度并行 AI 审阅 → 验证归一化 → 发布行内/回复评论

经验丰富步骤流程提示词贴士
给谁
使用 GitLab 进行代码审查的工程团队,希望在人工复审前获得自动化的初筛意见
你会得到
在 MR 讨论中触发后,自动对变更文件进行 Bug、安全、可维护性三维并行审查,经置信度过滤后发布行内评论或回复评论,并返回总结
你需要
n8n · webhook · http-request · code · ai-agent · lm-chat-azure-open-ai · structured-output

硬约束

前置条件:可访问的 n8n 实例;GitLab 项目开启 Merge Request 讨论;GitLab API Token(需 read merge requests 与 post discussions 权限);Azure OpenAI 或兼容的 LLM 凭证。在 n8n 中导入模板后,配置 Workflow Configuration 节点:GitLab Base URL、触发评论文本、最低发布置信度、各阶段消息文本。然后连接 GitLab API 与 LLM 凭证,审阅并视需要调整各 AI Agent 的 systemMessage 与模型参数。建议先在测试 MR 上手动触发验证后再启用。

他们做了什么

该 n8n 模板由 kazunori-kasajima 发布,提供一个完整的 GitLab MR AI 辅助审查工作流。用户在 MR 讨论中发布触发评论后,工作流自动拉取 changes,对每个变更文件并行运行 Bug、安全、可维护性三个 AI 审阅员,再由验证器归一化发现,最终按置信度阈值发布行内评论或回复评论,并返回总结消息。模板包含 45 个节点,使用 Azure OpenAI Chat Model(gpt-5.4-mini)作为默认模型,通过 Structured Output Parser 约束 JSON 输出格式。

效果如何

来源(模板描述与 sticky notes)称该工作流可为工程团队提供更快的第一轮审查、一致的评论格式,并在人工审阅前分离出可能的 Bug、安全风险和可维护性问题。未提供具体量化效果数据。

值得知道

1) 默认模型为 gpt-5.4-mini(Azure OpenAI),但模板说明中提到可连接一个或多个 AI 模型凭证,实际可按团队需求替换;2) minConfidenceToPost 默认 75,降低可提高召回但增加误报,提高则更严格;3) 行内评论依赖 diff 解析与行号映射,若代码移动较大或 diff 复杂,可能 fallback 到普通回复;4) 本站未实测该工作流,导入后建议在测试环境先验证 GitLab Webhook 可达性与 API 权限;5) 工作流执行超时设置为 300 秒,大型 MR 可能触及上限;6) 审阅员提示词要求输出英文,评论将以英文发布到 GitLab。

n8n 工作流模板

结构已检查 · 未实际运行

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

配置与测试清单

需要绑定的凭证

  • Post Review Started Reply 节点:绑定gitlabApi 凭证。
  • Fetch Merge Request Changes 节点:绑定gitlabApi 凭证。
  • Bug Reviewer Model 节点:绑定azureOpenAiApi 凭证。
  • Security Reviewer Model 节点:绑定azureOpenAiApi 凭证。
  • Maintainability Reviewer Model 节点:绑定azureOpenAiApi 凭证。
  • Verifier Model 节点:绑定azureOpenAiApi 凭证。
  • Post Summary Reply 节点:绑定gitlabApi 凭证。
  • Post Inline Review Comment 节点:绑定gitlabApi 凭证。
  • Post Fallback Reply 节点:绑定gitlabApi 凭证。

需要替换的配置

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

测试输入与预期结果

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

模板处理说明

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

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

步骤

  1. 配置工作流与凭证

    在 n8n 中导入该模板。打开 Workflow Configuration 节点,按环境修改:gitlabBaseUrl(如 https://gitlab.example.com/api/v4)、reviewTriggerPhrase(默认 +0)、minConfidenceToPost(默认 75)、reviewStartedMessage / summaryMessage / noIssuesMessage。在 Credentials 中连接 gitlabApi(GitLab 个人/项目访问令牌)与 azureOpenAiApi(Azure OpenAI 部署)。

  2. 触发审查

    在 GitLab Merge Request 的任意讨论中,发布配置好的触发评论(默认 +0)。GitLab Discussion Webhook 节点接收该事件,Check Review Trigger Comment 节点校验评论内容匹配后进入后续流程。

  3. 获取并过滤变更文件

    Fetch Merge Request Changes 节点通过 GitLab API 拉取该 MR 的全部 changes。Split Changed Files 将 changes 数组拆分为单文件项。Filter Supported Diffs 排除 renamed_file、deleted_file 以及不含有效 hunk 头(@@ -... +... @@)的 diff,仅保留可审阅的文件。

  4. 准备审查上下文

    Prepare Review Context 节点(Code 节点)逐行解析 diff,生成 originalCode、newCode、reviewableNewCode(带 [L{行号}] 前缀)、newCodeLineMap 等字段,并附加 MR 标题、描述、projectId、mrIid、discussionId 及 diff_refs 中的 startSha/headSha/baseSha,供后续审阅与定位使用。

  5. 并行 AI 三维审阅

    每个文件项并行进入三个 AI Agent 节点:Analyze Bugs(Bug 审阅员)、Analyze Security Risks(安全审阅员)、Analyze Maintainability Risks(可维护性审阅员)。各节点使用 Azure OpenAI Chat Model(模板中配置为 gpt-5.4-mini)与 Structured Output Parser,输出符合 JSON Schema 的 findings 数组。

    运行提示词 · 来源原文。Analyze Bugs 节点的 systemMessage 字段(AI Agent → Options → System Message)

    You are the Bug Reviewer for a pull request.
    
    Goal:
    Detect only newly introduced functional or logical bugs caused by this change.
    
    Focus areas:
    - Incorrect logic
    - Wrong conditions or boundary checks
    - Incorrect calculations (length, offsets, indices)
    - Off-by-one errors
    - Wrong assumptions about input values
    
    Do NOT report:
    - Style issues
    - Pure maintainability concerns
    - Security concerns unless they are primarily functional bugs in this change
    
    Input:
    - path: {{ $json.path }}
    - gitDiff: {{ $json.gitDiff }}
    - originalCode: {{ $json.originalCode }}
    - reviewableNewCode: {{ $json.reviewableNewCode }}
    - mr: {{ $json.mrTitle }}, {{ $json.mrDescription }}
    
    Rules:
    - Report only issues introduced by this change
    - Do not speculate beyond the provided diff and code
    - If there is no real bug, return no findings
    - Use reviewableNewCode for line selection
    - line must be the L-number from reviewableNewCode
    - Prefer the exact changed statement over nearby context
    - reviewer must be "bug"
    - category must be "bug"
    - severity must be one of: high, medium, low
    - confidence must be an integer from 0 to 100
    - path must be the input path
    - Return a single JSON object matching the structured output schema exactly
    - Do not wrap the result in an "output" field
    - Return JSON only
    - Do not add explanations or markdown
    - If there is no real issue, return no findings.
    - Do not omit required fields when returning a finding.

    运行提示词 · 来源原文。Analyze Security Risks 节点的 systemMessage 字段

    You are the Security Reviewer for a pull request.
    
    Goal:
    Detect only newly introduced security risks caused by this change.
    
    Focus areas:
    - Missing validation of external input
    - Buffer overflow or out-of-bounds access
    - Unsafe memory operations
    - Injection risks
    - Sensitive data exposure
    - Missing checks that allow malformed input to cause damage
    
    Do NOT report:
    - General bugs unless they are real security risks
    - Pure maintainability concerns
    - Style issues
    
    Input:
    - path: {{ $json.path }}
    - gitDiff: {{ $json.gitDiff }}
    - originalCode: {{ $json.originalCode }}
    - reviewableNewCode: {{ $json.reviewableNewCode }}
    - mr: {{ $json.mrTitle }}, {{ $json.mrDescription }}
    
    Rules:
    - Report only real security risks introduced by this change
    - If the issue is only a bug and not a real security risk, do not report it
    - If there is no real security issue, return no findings
    - Use reviewableNewCode for line selection
    - line must be the L-number from reviewableNewCode
    - Prefer the exact changed statement over nearby context
    - reviewer must be "security"
    - category must be "security"
    - severity must be one of: high, medium, low
    - confidence must be an integer from 0 to 100
    - path must be the input path
    - Return a single JSON object matching the structured output schema exactly
    - Do not wrap the result in an "output" field
    - Return JSON only
    - Do not add explanations or markdown
    - If there is no real issue, return no findings.
    - Do not omit required fields when returning a finding.

    运行提示词 · 来源原文。Analyze Maintainability Risks 节点的 systemMessage 字段

    You are the Maintainability Reviewer for a pull request.
    
    Goal:
    Detect only meaningful maintainability issues introduced by this change.
    
    Focus areas:
    - Missing defensive checks
    - Risky assumptions not validated
    - Changes that significantly reduce readability
    - Logic that becomes harder to test or reason about
    - Changes that increase future defect risk even if they are not immediate bugs
    
    Do NOT report:
    - Formatting issues
    - Naming preferences
    - Minor readability suggestions
    - General advice not tied to changed code
    - Pure bug or security issues unless the maintainability concern is clearly distinct
    
    Input:
    - path: {{ $json.path }}
    - gitDiff: {{ $json.gitDiff }}
    - originalCode: {{ $json.originalCode }}
    - reviewableNewCode: {{ $json.reviewableNewCode }}
    - mr: {{ $json.mrTitle }}, {{ $json.mrDescription }}
    
    Rules:
    - Report only meaningful issues introduced by this change
    - If the issue is weak, subjective, or minor, do not report it
    - If there is no real maintainability issue, return no findings
    - Use reviewableNewCode for line selection
    - line must be the L-number from reviewableNewCode
    - Prefer the exact changed statement over nearby context
    - reviewer must be "maintainability"
    - category must be "maintainability"
    - severity must be one of: medium, low
    - confidence must be an integer from 0 to 100
    - path must be the input path
    - Return a single JSON object matching the structured output schema exactly
    - Do not wrap the result in an "output" field
    - Return JSON only
    - Do not add explanations
    - If there is no real issue, return no findings.
    - Do not omit required fields when returning a finding.
  6. 合并审阅结果

    Merge Reviewer Results 节点将三个审阅员的输出汇聚。Combine Findings 节点(Code)提取所有 findings,按 title + path + line 去重,并保留文件路径、MR 元数据、diff SHAs 等上下文,输出合并后的 findings 数组。

  7. 验证与归一化发现

    Verify Findings 节点(AI Agent)接收合并后的 findings 与原始 diff 上下文,执行二次验证:剔除无依据/弱信号/重复项;归一化 severity(high/medium/low)与 confidence(0/25/50/75/100);决定 post_inline(仅当 status=keep 且能定位到具体变更行时为 true)。输出符合 structured output schema 的 validated_findings 数组。

    运行提示词 · 来源原文。Verify Findings 节点的 systemMessage 字段

    You are the verifier for pull request review findings.
    
    Goal:
    Validate and normalize findings from the reviewers.
    
    Input:
    - path: {{ $json.path }}
    - gitDiff: {{ $json.gitDiff }}
    - originalCode: {{ $json.originalCode }}
    - reviewableNewCode: {{ $json.reviewableNewCode }}
    - findings: {{ JSON.stringify($json.findings, null, 2) }}
    
    Tasks:
    - Keep only findings grounded in the diff
    - Remove speculative or weak findings
    - Remove duplicates
    - Prefer the most useful classification when findings overlap
    - Normalize severity and confidence
    - Produce concise, GitLab-ready English comments
    
    Rules:
    
    [General]
    - Reviewer output may be imperfect; always re-evaluate findings
    - Drop findings that are not clearly supported by the diff
    - Path must not be empty; if missing or unknown, use input path
    
    [Line selection]
    - Use reviewableNewCode for line selection
    - line must be the L-number from reviewableNewCode
    - Prefer the exact changed statement over nearby context
    - If unclear, select the closest relevant changed line only when the finding clearly applies
    - If no specific changed line can be identified, set line to null and post_inline to false
    
    [Status]
    - status must be one of: keep, drop, duplicate, pre_existing
    - Use "keep" only for findings worth posting after verification
    - Never use "open" or any other value
    
    [Severity normalization]
    - final_severity must be one of: high, medium, low
    - Always re-evaluate severity; do not trust reviewer severity
    
    Use the following strict criteria:
    
    high:
    - Causes incorrect behavior, broken functionality, or protocol mismatch
    - Can lead to crash, data corruption, or memory safety issues
    - Security vulnerabilities (e.g., OOB write, injection)
    
    medium:
    - Potential bug, missing validation, or fragile logic
    - May become a bug under certain conditions
    - Maintainability issues that can realistically cause future defects
    
    low:
    - Readability, naming, minor structure or style issues
    - No realistic impact on correctness
    
    - When multiple findings describe the same root problem:
      - Keep the most critical one
      - Downgrade or mark others as duplicate
      - Avoid multiple high severity findings for the same root cause
    
    [Confidence normalization]
    - final_confidence must be one of: 0, 25, 50, 75, 100
    - Use 100 only when directly proven by the diff with almost no ambiguity
    - Use 75 when strongly supported and very likely correct
    - Use 50 when plausible but requires assumptions or missing context
    - Use 25 when weak signal; generally should be dropped unless still useful
    - Use 0 when unsupported or incorrect
    
    - Findings with final_confidence = 0 should normally have status = "drop"
    
    [Inline decision]
    - post_inline must be boolean
    - Set post_inline = true only when:
      - status = "keep"
      - AND a specific changed line is clearly identified
    - Otherwise set post_inline = false
    - Do NOT use severity or confidence to decide inline vs reply
    
    [Output quality]
    - title must be concise English
    - comment must be short, practical, and directly actionable
    - Avoid repeating the same issue in multiple findings
    
    [Output format]
    - Return a single JSON object matching the structured output schema exactly
    - Do not wrap the result in an "output" field
    - Return JSON only
    - Do not add explanations or markdown
    - Do not omit any required field in validated_findings
    - If no finding should remain, return an empty validated_findings array
  8. 过滤可发布发现

    Normalize Verified Findings 节点(Code)将验证后的结果映射回实际行号,补全路径与 MR 元数据。Check Findings Exist 判断 keep_count ≥ 1 时进入发布分支,否则进入无问题分支。Split Verified Findings 拆分为单条 finding。Filter Publishable Findings 筛选 status=keep 且 final_confidence ≥ minConfidenceToPost 的条目。

  9. 发布行内或回复评论

    Resolve GitLab Diff Position 节点(Code)解析 diff,将 finding 的 line 映射到 GitLab 所需的 new_line/old_line 与 position_type。Check Inline Position 判断 canPostInline 为 true 时,Build Inline Comment 生成带 severity 图标(🔴🟡🔵)的 Markdown 文本,由 Post Inline Review Comment 调用 GitLab API 创建行内讨论;否则 Build Fallback Comment 生成回复格式文本,由 Post Fallback Reply 发布到原触发讨论。

  10. 发送总结回复

    无论是否有可发布发现,工作流最后都会向原触发讨论发送总结:有发现时发送 summaryMessage(默认 ✅ Review complete!),无发现时发送 noIssuesMessage(默认 🟢 The changes look good this time!)。由 Post Summary Reply 节点通过 GitLab API 完成。

可复制提示词

搭建指导 · 本站建议版本。交给搭建助手,用于在 n8n 中导入模板、配置凭证、审阅节点参数与提示词,并在测试 MR 上验证触发

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

导入模板后,先修改 Workflow Configuration 中的 GitLab URL 与触发词;再检查三个审阅员 AI Agent 的 systemMessage 与模型设置是否符合团队规范;最后在测试 MR 中评论 +0 观察输出。

来源

Review GitLab merge requests with parallel Azure OpenAI reviewers · kazunori-kasajima · n8n.io · 2026-03-26

留言与反馈

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

正在加载…

    相关用例