MR Comment Handler
Find the open MR for the current branch and address its review threads using glab. Run all glab commands with elevated network access.
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:
glab auth status
1) Resolve the MR for the current branch
Do a quick check so we know which MR we are about to operate on:
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.
2) Fetch unresolved discussions to /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.
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.
3) Summarize, triage, and ask once
- 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).
4) Implement fixes for the selected discussions
- 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.
1---2name: gitlab-address-comments3description: Help address review/issue comments on the open GitLab MR for the current branch using glab CLI. Use when the user wants help addressing review/issue comments on an open GitLab MR4---5
6# MR Comment Handler
7
8Find the open MR for the current branch and address its review threads using `glab`. Run all `glab` commands with elevated network access.
9
10## Prerequisites
11- Ensure `glab auth status` succeeds (via `glab auth login` or `GITLAB_TOKEN`).
12- Ensure `glab` is at least v1.80.4.
13- When sandboxing blocks network calls, rerun with `sandbox_permissions=require_escalated`.
14- Sanity check auth up front:
15```bash
16glab auth status
17```
18
19## 1) Resolve the MR for the current branch
20Do a quick check so we know which MR we are about to operate on:
21```bash
22branch="$(git rev-parse --abbrev-ref HEAD)"
23glab mr view "$branch" --output json
24```
25If this fails, the fetch script below will still try to locate the MR by `source_branch`.
26
27## 2) Fetch unresolved discussions to `/tmp`
28Use 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.
29```bash
30skill_dir="<path-to-skill>"
31branch="$(git rev-parse --abbrev-ref HEAD)"
32safe_branch="${branch//\//_}"
33out="/tmp/${safe_branch}_mr_open_discussions.json"
34python "$skill_dir/scripts/fetch_comments.py" --open-comments --output "$out"
35```
36If you want the full payload (including resolved discussions), drop `--open-comments`.
37
38## 3) Summarize, triage, and ask once
39- Load the JSON and number each unresolved discussion.
40- Start with a compact summary list instead of dumping full threads.
41- Sort by: unresolved first (already filtered), then most recently updated.
42- When possible, group or label by file path to reduce context switching.
43- In the summary list, show: number, discussion id, author, file:line (if present), and a one-line summary.
44- Ask for a batch selection in one shot. Accept: `1,3,5-7`, `all`, `none`, or `top N`.
45- If the user does not choose, suggest a small default set (for example `top 3`) with a short rationale.
46- Only after selection, show the full thread and code context for the selected numbers.
47- When showing code context, include 3 lines before and after and clearly mark the referenced line(s).
48
49## 4) Implement fixes for the selected discussions
50- Apply focused fixes that address the selected threads.
51- Run the most relevant tests or checks you can in-repo.
52- Report back with: what changed, which discussion numbers were addressed, and any follow-ups.
53
54Notes:
55- If `glab` hits auth or rate issues, prompt the user to run `glab auth login` or re-export `GITLAB_TOKEN`, then retry.
56- If no open MR is found for the branch, say so clearly and ask for the MR URL or IID.
57- Do not prompt “address or skip?” one comment at a time unless the user explicitly asks for that mode.