gitlab-address-comments

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

MR Comment Handler

MR评论处理指南

Find the open MR for the current branch and address its review threads using
glab
. Run all
glab
commands with elevated network access.
借助
glab
查找当前分支对应的开放MR并处理其评审线程。所有
glab
命令需使用提升的网络权限运行。

Prerequisites

前提条件

  • Ensure
    glab auth status
    succeeds (via
    glab auth login
    or
    GITLAB_TOKEN
    ).
  • Ensure
    glab
    is at least v1.80.4.
  • When sandboxing blocks network calls, rerun with
    sandbox_permissions=require_escalated
    .
  • Sanity check auth up front:
bash
glab auth status
  • 确保
    glab auth status
    执行成功(可通过
    glab auth login
    或配置
    GITLAB_TOKEN
    实现)。
  • 确保
    glab
    版本至少为v1.80.4。
  • 当沙箱环境阻止网络调用时,需添加参数
    sandbox_permissions=require_escalated
    重新运行。
  • 预先进行身份验证合理性检查:
bash
glab auth status

1) Resolve the MR for the current branch

1) 定位当前分支对应的MR

Do a quick check so we know which MR we are about to operate on:
bash
branch="$(git rev-parse --abbrev-ref HEAD)"
glab mr view "$branch" --output json
If this fails, the fetch script below will still try to locate the MR by
source_branch
.
先快速检查,明确我们要操作的MR:
bash
branch="$(git rev-parse --abbrev-ref HEAD)"
glab mr view "$branch" --output json
如果此命令失败,下方的获取脚本会尝试通过
source_branch
定位MR。

2) Fetch unresolved discussions to
/tmp

2) 将未解决的讨论内容获取到
/tmp
目录

Use the local script to fetch MR discussions via
glab api
. This filters out bot/system-only threads and returns unresolved discussions when
--open-comments
is set.
bash
skill_dir="<path-to-skill>"
branch="$(git rev-parse --abbrev-ref HEAD)"
safe_branch="${branch//\//_}"
out="/tmp/${safe_branch}_mr_open_discussions.json"
python "$skill_dir/scripts/fetch_comments.py" --open-comments --output "$out"
If you want the full payload (including resolved discussions), drop
--open-comments
.
使用本地脚本通过
glab api
获取MR讨论内容。添加
--open-comments
参数时,会过滤掉机器人/系统专属线程,仅返回未解决的讨论。
bash
skill_dir="<path-to-skill>"
branch="$(git rev-parse --abbrev-ref HEAD)"
safe_branch="${branch//\//_}"
out="/tmp/${safe_branch}_mr_open_discussions.json"
python "$skill_dir/scripts/fetch_comments.py" --open-comments --output "$out"
如果需要完整的返回内容(包括已解决的讨论),请移除
--open-comments
参数。

3) Summarize, triage, and ask once

3) 总结、分类并一次性确认

  • Load the JSON and number each unresolved discussion.
  • Start with a compact summary list instead of dumping full threads.
  • Sort by: unresolved first (already filtered), then most recently updated.
  • When possible, group or label by file path to reduce context switching.
  • In the summary list, show: number, discussion id, author, file:line (if present), and a one-line summary.
  • Ask for a batch selection in one shot. Accept:
    1,3,5-7
    ,
    all
    ,
    none
    , or
    top N
    .
  • If the user does not choose, suggest a small default set (for example
    top 3
    ) with a short rationale.
  • Only after selection, show the full thread and code context for the selected numbers.
  • When showing code context, include 3 lines before and after and clearly mark the referenced line(s).
  • 加载JSON文件,为每个未解决的讨论编号。
  • 先展示简洁的总结列表,而非完整的线程内容。
  • 排序规则:优先显示未解决的讨论(已过滤),其次按最近更新时间排序。
  • 尽可能按文件路径分组或标记,减少上下文切换。
  • 在总结列表中展示:编号、讨论ID、作者、文件:行号(若存在)以及一行摘要。
  • 一次性请求用户批量选择,支持的格式:
    1,3,5-7
    all
    none
    top N
  • 若用户未做出选择,建议一个小型默认集合(例如
    top 3
    )并附上简短理由。
  • 仅在用户选择后,才展示所选编号对应的完整线程及代码上下文。
  • 展示代码上下文时,需包含引用行前后各3行内容,并清晰标记引用行。

4) Implement fixes for the selected discussions

4) 针对选中的讨论内容实施修复

  • Apply focused fixes that address the selected threads.
  • Run the most relevant tests or checks you can in-repo.
  • Report back with: what changed, which discussion numbers were addressed, and any follow-ups.
Notes:
  • If
    glab
    hits auth or rate issues, prompt the user to run
    glab auth login
    or re-export
    GITLAB_TOKEN
    , then retry.
  • If no open MR is found for the branch, say so clearly and ask for the MR URL or IID.
  • Do not prompt “address or skip?” one comment at a time unless the user explicitly asks for that mode.
  • 针对选中的线程进行精准修复。
  • 在仓库内运行最相关的测试或检查。
  • 反馈内容包括:修改内容、已处理的讨论编号以及后续待办事项。
注意事项:
  • glab
    遇到身份验证或调用频率限制问题,提示用户运行
    glab auth login
    或重新导出
    GITLAB_TOKEN
    ,然后重试。
  • 若未找到当前分支对应的开放MR,需明确告知用户,并请求提供MR的URL或IID。
  • 除非用户明确要求,否则不要逐个评论询问“处理还是跳过?”。