name: fix-discussion description: Fix GitLab MR discussions by modifying code, posting a reply explaining the fix, and resolving the discussion. Supports single or batch processing. Korean triggers: discussion 수정, 디스커션 해결, 코멘트 반영, 리뷰 반영, discussion resolve, 피드백 반영. user-invocable: true
Fix Discussion
⚠️ CRITICAL: MANDATORY WORKFLOW
ALL THREE STEPS ARE REQUIRED. DO NOT STOP AFTER CODE MODIFICATION.
┌─────────────────┐ ┌─────────────────┐ ┌─────────────────┐
│ 1. Code Fix │ → │ 2. Post Reply │ → │ 3. Resolve │
│ (Edit tool) │ │ (glab api) │ │ (glab api) │
└─────────────────┘ └─────────────────┘ └─────────────────┘
❌ STOP HERE = INCOMPLETE TASK
For EACH discussion, you MUST:
- ✅ Modify the code (Phase 3)
- ✅ Post a reply comment explaining the fix (Phase 4) - MANDATORY
- ✅ Resolve the discussion (Phase 5) - MANDATORY
FAILURE CRITERIA: If you only modify code without posting reply and resolving, the task is NOT COMPLETE.
Overview
Addresses GitLab MR discussion feedback through a code fix → reply → resolve workflow.
Key Features:
- Code Modification: Fix issues pointed out in the discussion
- Auto Reply: Generate explanatory reply describing the fix
- Auto Resolve: Mark discussion as resolved
- Batch Processing: Handle multiple discussions in one go
- Change Tracking: Summary of all modifications
When to Use
Use this skill when:
- Addressing discussions identified by
mr_discussions()MCP tool - Implementing reviewer feedback
- Batch processing multiple discussions
- Processing issues from
INLINE_DISCUSSION.json(from mr-review)
Do NOT use when:
- Discussion content is unclear (discuss with reviewer first)
- Comment is opinion-based, not requiring code changes
Workflow
Phase 0: Task Registration
⚠️ CRITICAL: DO NOT SKIP PHASE 0
Objective: Register all Phases as Tasks to track progress throughout the fix-discussion workflow.
Register the following Phases in order using TaskCreate:
| Task | subject | activeForm |
|---|---|---|
| Phase 1 | Gather Discussion Info | Gathering discussion info |
| Phase 2 | Analyze Comment | Analyzing comment |
| Phase 3 | Modify Code | Modifying code |
| Phase 4 | Post Reply | Posting reply |
| Phase 5 | Resolve Discussion | Resolving discussion |
| Phase 6 | Report Results | Reporting results |
Task Tracking Rules:
- On Phase entry:
TaskUpdate(taskId, status: "in_progress") - On Phase completion:
TaskUpdate(taskId, status: "completed") - Only one Phase should be
in_progressat any time
Phase 1: Gather Discussion Info
📋 Task Tracking: Mark this Phase's Task as
in_progresson entry,completedon completion.
1-1. Identify Source
Discussions can come from two sources:
Source A: GitLab MR Discussions (most common)
# Get discussion from GitLab
glab api "projects/:fullpath/merge_requests/${MR_IID}/discussions/${DISCUSSION_ID}" | jq '.'
Source B: INLINE_DISCUSSION.json (from mr-review skill)
# Read local file generated by mr-review
cat INLINE_DISCUSSION.json | jq '.[]'
1-2. Extract Required Info
For each discussion, extract:
file: File pathline: Line numberdescription: Issue description (what to fix)suggested_code: Suggested fix (if available)discussion_id: GitLab discussion ID (for reply/resolve)
1-3. Get Discussion ID from GitLab
If using INLINE_DISCUSSION.json, you need to find the corresponding GitLab discussion ID:
# Find discussion by file and line
glab api "projects/:fullpath/merge_requests/${MR_IID}/discussions" | jq --arg file "src/api/user.ts" --arg line "45" '
.[] | select(
.notes[0].position.new_path == $file and
(.notes[0].position.new_line | tostring) == $line
) | .id
'
Phase 2: Analyze Comment
📋 Task Tracking: Mark this Phase's Task as
in_progresson entry,completedon completion.
2-1. Parse Comment Content
Extract from comment:
- Severity: Critical, High, Medium, etc.
- Issue Description: What's the problem
- Suggested Fix: Proposed code (if provided)
2-2. Create Fix Plan
## Fix Plan
**File**: src/api/user.ts
**Line**: 45
**Issue**: SQL Injection vulnerability
**Fix Approach**: Use Prepared Statement
**Before**:
```typescript
const query = `SELECT * FROM users WHERE id = ${userId}`;
After:
const query = 'SELECT * FROM users WHERE id = ?';
const result = await db.execute(query, [userId]);
---
### Phase 3: Modify Code
> 📋 **Task Tracking**: Mark this Phase's Task as `in_progress` on entry, `completed` on completion.
**3-1. Read File**
```typescript
Read({ file_path: "/path/to/project/src/api/user.ts" })
3-2. Apply Fix
Edit({
file_path: "/path/to/project/src/api/user.ts",
old_string: "const query = `SELECT * FROM users WHERE id = ${userId}`;",
new_string: "const query = 'SELECT * FROM users WHERE id = ?';\nconst result = await db.execute(query, [userId]);"
})
2-3. Verify Fix
Re-read the modified lines to confirm the change was applied correctly.
⚠️ DO NOT STOP HERE. PROCEED TO PHASE 3 IMMEDIATELY.
Phase 4: Post Reply [MANDATORY]
📋 Task Tracking: Mark this Phase's Task as
in_progresson entry,completedon completion.
⚠️ THIS PHASE IS MANDATORY. YOU MUST POST A REPLY TO GITLAB.
4-1. Generate Reply Content
✅ **Fixed**
**Changes**:
- Changed to Prepared Statement pattern
- Applied parameter binding
**Updated code**:
```typescript
const query = 'SELECT * FROM users WHERE id = ?';
const result = await db.execute(query, [userId]);
🤖 Generated by Claude Code
**4-2. Post Reply via GitLab API**
```bash
# MANDATORY: Add reply to discussion
glab api --method POST \
"projects/:fullpath/merge_requests/${MR_IID}/discussions/${DISCUSSION_ID}/notes" \
-f body="✅ **Fixed**
**Changes**:
- Changed to Prepared Statement pattern
- Applied parameter binding
---
🤖 Generated by Claude Code"
4-3. Verify Reply Posted
# Confirm reply was added
glab api "projects/:fullpath/merge_requests/${MR_IID}/discussions/${DISCUSSION_ID}" \
| jq '.notes | length'
# Should be > 1 (original + your reply)
⚠️ DO NOT STOP HERE. PROCEED TO PHASE 4 IMMEDIATELY.
Phase 5: Resolve Discussion [MANDATORY]
📋 Task Tracking: Mark this Phase's Task as
in_progresson entry,completedon completion.
⚠️ THIS PHASE IS MANDATORY. YOU MUST RESOLVE THE DISCUSSION.
5-1. Mark as Resolved
# MANDATORY: Resolve discussion
glab api --method PUT \
"projects/:fullpath/merge_requests/${MR_IID}/discussions/${DISCUSSION_ID}" \
-f resolved=true
5-2. Verify Resolution
# Confirm resolved status
glab api "projects/:fullpath/merge_requests/${MR_IID}/discussions/${DISCUSSION_ID}" \
| jq '.notes[0].resolved'
# Should return: true
Phase 6: Report Results
📋 Task Tracking: Mark this Phase's Task as
in_progresson entry,completedon completion.
6-1. Single Discussion Result
## ✅ Discussion Fixed
**Discussion ID**: abc123def456
**File**: src/api/user.ts:45
**Issue**: SQL Injection vulnerability
### Status Checklist
- [x] Code modified
- [x] Reply posted to GitLab
- [x] Discussion resolved
6-2. Batch Processing Result
## Discussion Fix Summary
| # | File | Code | Reply | Resolved | Note |
|---|------|------|-------|----------|------|
| 1 | src/api/user.ts:45 | ✅ | ✅ | ✅ | SQL Injection |
| 2 | src/services/auth.ts:78 | ✅ | ✅ | ✅ | Error handling |
| 3 | src/utils/validation.ts:12 | ⏭️ | ⏭️ | ⏭️ | Skipped |
**Processed**: 2/3 complete
### Next Steps
```bash
git add -A && git commit -m "fix: address review feedback"
git push
---
## Batch Processing
When handling multiple discussions:
**Process Flow for Each Discussion:**
for each discussion:
✅ Read and analyze comment
✅ Modify code
✅ Post reply (MANDATORY)
✅ Resolve (MANDATORY)
✅ Record result end
Output summary with checklist
Suggest git commit
**Command Examples:**
"Fix all discussions" "Fix Discussion #1 and #3 only" "Fix discussions in src/api/*.ts files only"
---
## Using with INLINE_DISCUSSION.json
When `mr-review` generates `INLINE_DISCUSSION.json`, you can use it as input:
**1. Read INLINE_DISCUSSION.json**
```bash
cat INLINE_DISCUSSION.json
2. For each issue in the JSON:
{
"file": "src/api/user.ts",
"line": 45,
"severity": "🔴 Critical",
"title": "SQL Injection vulnerability",
"description": "User input directly used in query",
"suggested_code": "const query = 'SELECT * FROM users WHERE id = ?';"
}
3. Find corresponding GitLab Discussion ID:
DISCUSSION_ID=$(glab api "projects/:fullpath/merge_requests/${MR_IID}/discussions" | jq -r --arg file "src/api/user.ts" --arg line "45" '
.[] | select(
.notes[0].position.new_path == $file and
(.notes[0].position.new_line | tostring) == $line
) | .id
')
4. Then proceed with Phase 3-5 (Code fix → Reply → Resolve)
glab CLI Reference
Post Reply to Discussion
glab api --method POST \
"projects/:fullpath/merge_requests/<MR_IID>/discussions/<DISCUSSION_ID>/notes" \
-f body="Reply content"
Resolve Discussion
glab api --method PUT \
"projects/:fullpath/merge_requests/<MR_IID>/discussions/<DISCUSSION_ID>" \
-f resolved=true
Find Discussion by File/Line
glab api "projects/:fullpath/merge_requests/<MR_IID>/discussions" | jq --arg file "path/to/file.ts" --arg line "123" '
.[] | select(
.notes[0].position.new_path == $file and
(.notes[0].position.new_line | tostring) == $line
)
'
Unresolve Discussion (if needed)
glab api --method PUT \
"projects/:fullpath/merge_requests/<MR_IID>/discussions/<DISCUSSION_ID>" \
-f resolved=false
Error Handling
Code Modification Failed
⚠️ Discussion #1 code modification failed.
**Cause**: Target code not found or already changed.
**Next Steps**:
1. Manually check file
2. Apply fix manually
3. **Still proceed with Phase 4-5** (post reply explaining situation, then resolve)
API Permission Error
❌ Discussion resolve failed.
**Cause**: Insufficient API permissions or already resolved.
**Troubleshooting**:
1. Check glab auth: `glab auth status`
2. Verify discussion state
3. Confirm write access to MR
Discussion ID Not Found
❌ Cannot find GitLab discussion for file:line
**Cause**: The discussion may not exist on GitLab yet, or file/line mismatch.
**Next Steps**:
1. Use `mr_discussions()` MCP tool to see actual discussions
2. Verify file path and line number
3. The issue may be from local review only (INLINE_DISCUSSION.json) - code fix is sufficient
Completion Checklist
Before reporting task complete, verify ALL items:
- Code modification applied
- Reply posted to GitLab discussion
- Discussion marked as resolved
- Summary includes all three status indicators
If any item is unchecked, the task is NOT complete.
Integration
Full Workflow
1. mr-review → Creates INLINE_DISCUSSION.json + posts discussions to MR
2. mr_discussions() MCP → Review discussion list from GitLab
3. fix-discussion → Code fix + reply + resolve (ALL THREE STEPS)
4. git commit & push → Push changes
5. MR ready to merge
Related Skills
- mr_discussions() MCP: View discussion list (prerequisite)
- mr-review: MR code review and discussion creation