|
45 | 45 | env: |
46 | 46 | GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
47 | 47 |
|
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 | | - |
74 | 48 | - name: Run Comprehensive Review |
75 | 49 | uses: anthropics/claude-code-action@v1 |
76 | 50 | with: |
@@ -137,16 +111,8 @@ jobs: |
137 | 111 | [Overall assessment with approval/disapproval reasoning] |
138 | 112 | ``` |
139 | 113 | |
140 | | - 5. Post review (MANDATORY FINAL STEP - use single efficient command) |
| 114 | + 5. Post review (MANDATORY FINAL STEP) |
141 | 115 | ```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 |
150 | 116 | gh pr comment ${{ github.event.pull_request.number }} --repo ${{ github.repository }} --body "YOUR_REVIEW_HERE" |
151 | 117 | ``` |
152 | 118 | |
@@ -180,3 +146,42 @@ jobs: |
180 | 146 | --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:*)" |
181 | 147 | --max-turns ${{ steps.critical_paths.outputs.is_critical == 'true' && '90' || '65' }} |
182 | 148 | --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