gitlab

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

GitLab Skill

GitLab Skill

Use the
glab
CLI to interact with GitLab. The primary workflow is MR Review — but this skill handles any GitLab operation the user needs.
使用
glab
CLI 与 GitLab 交互。核心工作流是 MR 评审,但本 skill 支持处理用户需要的任何 GitLab 操作。

URL Parsing

URL 解析

When given a GitLab MR URL like
https://gitlab.com/group/subgroup/project/-/merge_requests/42
:
  • repo_ref: strip
    https://
    and everything from
    /-/
    onward →
    gitlab.com/group/subgroup/project
  • mr_id: extract the number after
    merge_requests/
    42
These two values power most glab commands:
glab mr <cmd> <mr_id> --repo <repo_ref>
当收到类似
https://gitlab.com/group/subgroup/project/-/merge_requests/42
的 GitLab MR URL 时:
  • repo_ref:去掉
    https://
    以及
    /-/
    之后的所有内容 →
    gitlab.com/group/subgroup/project
  • mr_id:提取
    merge_requests/
    之后的数字 →
    42
这两个值是大多数 glab 命令的核心参数:
glab mr <cmd> <mr_id> --repo <repo_ref>

MR Review Workflow

MR 评审工作流

When the user asks to review a MR, run this pipeline:
1. Fetch MR info, diff, and existing comments
2. Read & summarize existing comments (understand what's already discussed)
3. code-reviewer + security + qa → review in PARALLEL (with comment context)
4. Compose Thai comment from template
5. Post comment to the MR
当用户要求评审某个 MR 时,运行以下流程:
1. 拉取 MR 信息、diff 和已有评论
2. 阅读并总结已有评论(了解已经讨论过的内容)
3. code-reviewer + security + qa → 并行评审(传入评论上下文)
4. 基于模板撰写泰语评论
5. 将评论发布到对应 MR

Step 1: Fetch

步骤 1:拉取信息

bash
glab mr view <mr_id> --repo <repo_ref> --output json
glab mr diff <mr_id> --repo <repo_ref>
glab mr note list <mr_id> --repo <repo_ref>
Extract from the view output: MR title, source branch, target branch, author.
bash
glab mr view <mr_id> --repo <repo_ref> --output json
glab mr diff <mr_id> --repo <repo_ref>
glab mr note list <mr_id> --repo <repo_ref>
从 view 命令的输出中提取:MR 标题、源分支、目标分支、作者。

Step 2: Read Existing Comments

步骤 2:读取已有评论

Before diving into the review, read through all existing MR comments/notes fetched in Step 1. This gives crucial context — other reviewers may have already flagged issues, the author may have explained design decisions, or there may be ongoing discussions that affect how you should review. Summarize the key points:
  • Issues already raised by other reviewers
  • Author's explanations or decisions
  • Unresolved discussions that need attention
  • Resolved items (avoid duplicating feedback)
This prevents the review from repeating what's already been said and helps focus on gaps that haven't been addressed yet.
在开始评审前,通读步骤 1 拉取到的所有 MR 已有评论/备注。这会提供关键上下文——其他评审者可能已经标记了问题,作者可能已经解释了设计决策,或者存在仍在进行中的讨论,这些都会影响你的评审方式。总结核心要点:
  • 其他评审者已经提出的问题
  • 作者的解释或决策
  • 需要关注的未解决讨论
  • 已解决项(避免重复反馈)
这可以避免评审内容重复已有讨论,帮助聚焦于还没有处理的空缺部分。

Step 3: Parallel Review

步骤 3:并行评审

Read the project's
CLAUDE.md
if available (for conventions). Then spawn all three agents at the same time, including a summary of existing comments so reviewers have full context:
Agent(
  description: "Code review MR diff",
  subagent_type: "code-reviewer",
  model: "opus",
  prompt: """
[code-reviewer agent instructions — read from ~/.claude/agents/code-reviewer.agent.md]

---
如果项目存在
CLAUDE.md
则先读取(了解规范)。然后同时启动三个 Agent,传入已有评论的总结,让评审者获得完整上下文:
Agent(
  description: "Code review MR diff",
  subagent_type: "code-reviewer",
  model: "opus",
  prompt: """
[code-reviewer agent 指令 — 读取自 ~/.claude/agents/code-reviewer.agent.md]

---

Project Conventions

项目规范

[relevant sections from CLAUDE.md if available, else omit]

[如果存在 CLAUDE.md 则提取相关部分,否则省略]

Existing MR Comments

已有 MR 评论

[summary of existing comments from Step 2 — issues raised, author explanations, unresolved discussions] Do NOT repeat issues that other reviewers have already flagged unless you have additional insight to add.

[步骤 2 得到的已有评论总结——提出的问题、作者解释、未解决讨论] 除非你有额外的见解补充,否则不要重复其他评审者已经标记过的问题。

Task

任务

Review the following MR diff for convention compliance.
MR: !<mr_id> — <mr_title> Branch: <source><target>
评审以下 MR diff 是否符合规范。
MR: !<mr_id> — <mr_title> 分支: <source><target>

Diff

Diff

<full diff output> """ )
Agent( description: "Security review MR diff", subagent_type: "security", model: "sonnet", prompt: """ [security agent instructions — read from ~/.claude/agents/security.agent.md]

<完整 diff 输出> """ )
Agent( description: "Security review MR diff", subagent_type: "security", model: "sonnet", prompt: """ [security agent 指令 — 读取自 ~/.claude/agents/security.agent.md]

Existing MR Comments

已有 MR 评论

[summary of existing comments from Step 2 — issues raised, author explanations, unresolved discussions] Do NOT repeat security concerns that have already been raised unless you have additional findings.

[步骤 2 得到的已有评论总结——提出的问题、作者解释、未解决讨论] 除非你有额外的发现,否则不要重复已经提出过的安全隐患。

Task

任务

Security review the following MR diff.
MR: !<mr_id> — <mr_title> Branch: <source><target>
对以下 MR diff 进行安全评审。
MR: !<mr_id> — <mr_title> 分支: <source><target>

Diff

Diff

<full diff output> """ )
Agent( description: "QA review MR diff", subagent_type: "qa", model: "sonnet", prompt: """ [qa agent instructions — read from ~/.claude/agents/qa.agent.md]

<完整 diff 输出> """ )
Agent( description: "QA review MR diff", subagent_type: "qa", model: "sonnet", prompt: """ [qa agent 指令 — 读取自 ~/.claude/agents/qa.agent.md]

Project Conventions

项目规范

[relevant sections from CLAUDE.md if available, else omit]

[如果存在 CLAUDE.md 则提取相关部分,否则省略]

Existing MR Comments

已有 MR 评论

[summary of existing comments from Step 2 — issues raised, author explanations, unresolved discussions] Do NOT repeat QA concerns that have already been raised unless you have additional findings.

[步骤 2 得到的已有评论总结——提出的问题、作者解释、未解决讨论] 除非你有额外的发现,否则不要重复已经提出过的 QA 相关问题。

Task

任务

QA review the following MR diff. Focus on:
  • Test coverage gaps (are new code paths tested?)
  • Missing edge case tests
  • Regression risks
  • Acceptance criteria validation (if available)
MR: !<mr_id> — <mr_title> Branch: <source><target>
对以下 MR diff 进行 QA 评审。重点关注:
  • 测试覆盖缺口(新代码路径是否有测试?)
  • 缺失的边界 case 测试
  • 回归风险
  • 验收标准验证(如果有提供)
MR: !<mr_id> — <mr_title> 分支: <source><target>

Diff

Diff

<full diff output> """ ) ```
Read the agent files from
~/.claude/agents/
before spawning, so the full agent instructions are included in the prompt.
<完整 diff 输出> """ )

在启动 Agent 前先从 `~/.claude/agents/` 读取对应 Agent 文件,确保完整的 Agent 指令都包含在提示词中。

Step 4: Compose Thai comment

步骤 4:撰写泰语评论

Read references/mr-review-template.md and fill in findings from all three agents (code-reviewer, security, qa).
读取 references/mr-review-template.md,填入三个 Agent(code-reviewer、security、qa)的所有发现。

Step 5: Post

步骤 5:发布

bash
glab mr note <mr_id> --repo <repo_ref> -m "<thai_comment>"
If
glab
is not authenticated or fails, output the review in the conversation instead and tell the user.

bash
glab mr note <mr_id> --repo <repo_ref> -m "<thai_comment>"
如果
glab
未认证或运行失败,则直接在对话中输出评审结果并告知用户。

Common glab Operations

常用 glab 操作

Use these directly via
Bash
when the user asks for something other than a full review:
TaskCommand
List open MRs
glab mr list --repo <repo_ref>
View MR details
glab mr view <mr_id> --repo <repo_ref>
Approve MR
glab mr approve <mr_id> --repo <repo_ref>
Check pipeline status
glab ci status --repo <repo_ref>
List pipelines
glab ci list --repo <repo_ref>
Retry a job
glab ci retry <job_id> --repo <repo_ref>
Add a note/comment
glab mr note <mr_id> --repo <repo_ref> -m "<text>"
For
--repo
, you can omit it if you're already inside the project directory (glab detects the remote automatically).
当用户要求的不是完整评审时,直接通过
Bash
运行以下命令:
任务命令
列出打开的 MR
glab mr list --repo <repo_ref>
查看 MR 详情
glab mr view <mr_id> --repo <repo_ref>
批准 MR
glab mr approve <mr_id> --repo <repo_ref>
检查流水线状态
glab ci status --repo <repo_ref>
列出流水线
glab ci list --repo <repo_ref>
重试任务
glab ci retry <job_id> --repo <repo_ref>
添加备注/评论
glab mr note <mr_id> --repo <repo_ref> -m "<text>"
对于
--repo
参数,如果你已经处于项目目录下可以省略(glab 会自动检测远程仓库)。

Error Handling

错误处理

  • glab not authenticated: tell the user to run
    glab auth login
  • glab command fails: output the review as conversation text instead of posting, explain what failed
  • Empty diff: note that the MR has no file changes and skip the review agents
  • Large diff (>500 lines): warn the user, proceed but note the review may miss details
  • glab 未认证:告知用户运行
    glab auth login
  • glab 命令运行失败:不在 MR 中发布评论,直接在对话中输出评审结果,解释失败原因
  • 空 diff:标注该 MR 没有文件变更,跳过评审 Agent
  • diff 过大(>500 行):警告用户,继续评审但标注可能会遗漏细节