Skip to content

Commit 834cffa

Browse files
committed
fix: better stale comment removal + correct YAML string escaping
1 parent 8ed1a08 commit 834cffa

File tree

2 files changed

+42
-37
lines changed

2 files changed

+42
-37
lines changed

.github/workflows/claude-issue-triage.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ jobs:
165165
166166
### STAGE 3: Solution Proposal (CONDITIONAL)${{ steps.analyze.outputs.severity == 'high' && '\n\n**⚠️ REQUIRED** - Critical issue, must propose fix' || '\n\n**OPTIONAL** - Propose fix if solution is clear and straightforward' }}
167167
168-
${{ steps.analyze.outputs.severity == 'high' && '**You MUST propose a fix for this critical issue:**' || '**Propose a fix only if:**\n- Root cause is clear\n- Fix is straightforward (< 50 lines changed)\n- You\'re confident it won\'t introduce regressions' }}
168+
${{ steps.analyze.outputs.severity == 'high' && '**You MUST propose a fix for this critical issue:**' || '**Propose a fix only if:**\n- Root cause is clear\n- Fix is straightforward (< 50 lines changed)\n- You''re confident it won''t introduce regressions' }}
169169
170170
#### 3.1 Design the Fix
171171
@@ -249,7 +249,7 @@ jobs:
249249
250250
**Comment Structure** (adapt based on investigation depth):
251251
252-
${{ steps.analyze.outputs.should_investigate == 'true' && '**For investigated issues:**\n\n```markdown\n## Investigation Results\n\nThanks for reporting this, @${{ github.event.issue.user.login }}! I\'ve performed a thorough analysis.\n\n### Classification\n- **Type:** [bug/feature/etc]\n- **Severity:** [P0-critical/P1-high/etc]\n- **Component:** [worker/ui/etc]\n\n### Root Cause Analysis\n[Detailed explanation of what\'s causing the issue]\n\n**Location:** `path/to/file.ts:123`\n\n**Introduced in:** PR #XXX (if found) or Commit ABC123\n\n### Proposed Solution\n[Explain the fix approach]\n\n### Status\n- ✅ PR #XXX created with proposed fix (if applicable)\n- ⏳ Requires manual review and testing\n- 📋 Added to backlog for team review (if no PR)\n\n### Next Steps\n[What happens next - PR review, team discussion, etc.]\n```' || '**For standard triage:**\n\n```markdown\nThanks for reporting this, @${{ github.event.issue.user.login }}!\n\n### Classification\n- **Labels:** [list applied labels]\n- **Priority:** [explanation of priority]\n\n[Context-specific response based on issue type]\n\n### Next Steps\nThe team will review this and provide updates.\n```' }}
252+
${{ steps.analyze.outputs.should_investigate == 'true' && '**For investigated issues:**\n\n```markdown\n## Investigation Results\n\nThanks for reporting this, @${{ github.event.issue.user.login }}! I''ve performed a thorough analysis.\n\n### Classification\n- **Type:** [bug/feature/etc]\n- **Severity:** [P0-critical/P1-high/etc]\n- **Component:** [worker/ui/etc]\n\n### Root Cause Analysis\n[Detailed explanation of what''s causing the issue]\n\n**Location:** `path/to/file.ts:123`\n\n**Introduced in:** PR #XXX (if found) or Commit ABC123\n\n### Proposed Solution\n[Explain the fix approach]\n\n### Status\n- ✅ PR #XXX created with proposed fix (if applicable)\n- ⏳ Requires manual review and testing\n- 📋 Added to backlog for team review (if no PR)\n\n### Next Steps\n[What happens next - PR review, team discussion, etc.]\n```' || '**For standard triage:**\n\n```markdown\nThanks for reporting this, @${{ github.event.issue.user.login }}!\n\n### Classification\n- **Labels:** [list applied labels]\n- **Priority:** [explanation of priority]\n\n[Context-specific response based on issue type]\n\n### Next Steps\nThe team will review this and provide updates.\n```' }}
253253
254254
---
255255

.github/workflows/claude-reviews.yml

Lines changed: 40 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -45,32 +45,6 @@ jobs:
4545
env:
4646
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
4747

48-
- name: Minimize Old Review Comments
49-
run: |
50-
echo "Collapsing previous review comments from github-actions[bot]..."
51-
52-
# Get all comments from github-actions[bot] on this PR
53-
OLD_REVIEWS=$(gh api repos/${{ github.repository }}/issues/${{ github.event.pull_request.number }}/comments \
54-
--jq '[.[] | select(.user.login == "github-actions[bot]") | select(.body | contains("## Code Review") or contains("🔒 **CRITICAL PATH SECURITY REVIEW**") or contains("## 🔍 Code Quality & Security Review")) | .id]')
55-
56-
if [ -n "$OLD_REVIEWS" ] && [ "$OLD_REVIEWS" != "[]" ]; then
57-
echo "Found old review comments to collapse"
58-
echo "$OLD_REVIEWS" | jq -r '.[]' | while read comment_id; do
59-
echo "Collapsing comment $comment_id"
60-
gh api repos/${{ github.repository }}/issues/comments/$comment_id -X PATCH \
61-
-f body="<details><summary>🔒 Previous review (outdated)</summary>
62-
63-
This review has been superseded by a newer review.
64-
</details>" || echo "Failed to collapse comment $comment_id"
65-
done
66-
echo "✓ Old comments collapsed"
67-
else
68-
echo "No old review comments found"
69-
fi
70-
env:
71-
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
72-
continue-on-error: true
73-
7448
- name: Run Comprehensive Review
7549
uses: anthropics/claude-code-action@v1
7650
with:
@@ -137,16 +111,8 @@ jobs:
137111
[Overall assessment with approval/disapproval reasoning]
138112
```
139113
140-
5. Post review (MANDATORY FINAL STEP - use single efficient command)
114+
5. Post review (MANDATORY FINAL STEP)
141115
```bash
142-
# Post new review (collapse old ones first if any exist)
143-
OLD_IDS=$(gh api repos/${{ github.repository }}/issues/${{ github.event.pull_request.number }}/comments --jq '[.[] | select(.user.login == "github-actions[bot]") | select(.body | startswith("## Code & Security Review")) | .id] | @csv' | tr -d '"')
144-
if [ -n "$OLD_IDS" ]; then
145-
for id in ${OLD_IDS//,/ }; do
146-
gh api -X PATCH repos/${{ github.repository }}/issues/comments/$id -f body="<details><summary>Outdated</summary></details>" &
147-
done
148-
wait
149-
fi
150116
gh pr comment ${{ github.event.pull_request.number }} --repo ${{ github.repository }} --body "YOUR_REVIEW_HERE"
151117
```
152118
@@ -180,3 +146,42 @@ jobs:
180146
--allowed-tools "mcp__github_inline_comment__create_inline_comment,Bash(gh issue view:*),Bash(gh issue list:*),Bash(gh search:*),Bash(gh pr comment:*),Bash(gh pr diff:*),Bash(gh pr view:*),Bash(gh pr edit:*),Bash(gh api:*)"
181147
--max-turns ${{ steps.critical_paths.outputs.is_critical == 'true' && '90' || '65' }}
182148
--model claude-sonnet-4-5-20250929
149+
150+
- name: Intelligent Comment Cleanup
151+
uses: anthropics/claude-code-action@v1
152+
if: always()
153+
with:
154+
github_token: ${{ secrets.GITHUB_TOKEN }}
155+
anthropic_api_key: ${{ secrets.ANTHROPIC_API_KEY }}
156+
prompt: |
157+
Clean up stale bot comments on PR #${{ github.event.pull_request.number }}.
158+
159+
**Task:**
160+
1. Fetch all comments on this PR
161+
2. Identify bot comments (users ending in [bot]) that are stale/outdated:
162+
- Old reviews superseded by newer ones
163+
- Old PR description suggestions
164+
- Previously collapsed/outdated markers
165+
- Progress/status comments from previous workflow runs
166+
3. Keep only the most recent comment per category per bot
167+
4. DELETE all stale comments (do not collapse)
168+
169+
**Get all comments:**
170+
```bash
171+
gh api repos/${{ github.repository }}/issues/${{ github.event.pull_request.number }}/comments --jq '.[] | {id, user: .user.login, body, created_at}'
172+
```
173+
174+
**Delete a comment:**
175+
```bash
176+
gh api repos/${{ github.repository }}/issues/comments/COMMENT_ID -X DELETE
177+
```
178+
179+
Be intelligent:
180+
- Preserve the newest useful comment in each category
181+
- Delete everything else that's redundant or stale
182+
- If unsure, keep the comment (conservative approach)
183+
184+
claude_args: |
185+
--allowed-tools "Bash(gh api repos/*/issues/*/comments:*),Bash(gh api repos/*/issues/comments/*:*)"
186+
--max-turns 8
187+
--model claude-haiku-4-5-20251001

0 commit comments

Comments
 (0)