Fix review script feedback #22
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: auto code review | |
| on: | |
| pull_request: | |
| types: [opened, synchronize, reopened] | |
| jobs: | |
| review: | |
| runs-on: [self-hosted, appendix-reviewer] | |
| permissions: | |
| pull-requests: write | |
| contents: read | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 | |
| - name: Fetch PR base | |
| shell: pwsh | |
| run: | | |
| git fetch origin ${{ github.base_ref }} --depth=1 | |
| - name: Get previous AI review SHA (if any) | |
| shell: pwsh | |
| env: | |
| GH_TOKEN: ${{ github.token }} | |
| run: | | |
| $pr = "${{ github.event.pull_request.number }}" | |
| $comments = gh api repos/${{ github.repository }}/issues/$pr/comments | ConvertFrom-Json | |
| $ai = $comments | Where-Object { $_.body -match "Reviewed-Head-SHA:" } | Select-Object -Last 1 | |
| if ($null -ne $ai) { | |
| $m = [regex]::Match($ai.body, "AI_REVIEW:HEAD_SHA=([0-9a-fA-F]{7,40})") | |
| if ($m.Success) { | |
| "PREV_SHA=$($m.Groups[1].Value)" | Out-File -FilePath $env:GITHUB_ENV -Append | |
| Write-Host "Found previous review SHA: $($m.Groups[1].Value)" | |
| } | |
| } else { | |
| Write-Host "No previous AI review comment found." | |
| } | |
| - name: Build diff (incremental if possible) | |
| shell: pwsh | |
| run: | | |
| git fetch origin ${{ github.base_ref }} --depth=1 | |
| if ($env:PREV_SHA) { | |
| # Validate that PREV_SHA exists in this checkout (force-push can break it) | |
| git cat-file -e "$env:PREV_SHA^{commit}" 2>$null | |
| if ($LASTEXITCODE -eq 0) { | |
| git diff --unified=3 $env:PREV_SHA...HEAD > diff.txt | |
| Write-Host "Using incremental diff: $env:PREV_SHA...HEAD" | |
| } else { | |
| Write-Host "PREV_SHA not found locally (maybe force-push). Falling back to full diff." | |
| git diff --unified=3 origin/${{ github.base_ref }}...HEAD > diff.txt | |
| } | |
| } else { | |
| git diff --unified=3 origin/${{ github.base_ref }}...HEAD > diff.txt | |
| Write-Host "Using full PR diff against base." | |
| } | |
| Get-Content diff.txt | Measure-Object -Line -Word -Character | Format-List | |
| - name: Run multi-agent local review | |
| shell: pwsh | |
| env: | |
| MODEL: qwen2.5:14b-instruct | |
| MAX_DIFF_CHARS: "80000" | |
| RETRY_ON_BAD_JSON: "1" | |
| # Set SHOW_DEBUG=1 to see detailed debug output in PR comment | |
| # SHOW_DEBUG: "1" | |
| run: | | |
| python .github/scripts/multi_agent_review.py 2>&1 | |
| if (-not (Test-Path review_comment.md)) { | |
| Write-Error "review_comment.md was not created - script may have failed silently" | |
| exit 1 | |
| } | |
| Write-Host "Review comment generated successfully" | |
| - name: Post comment to PR | |
| shell: pwsh | |
| env: | |
| GH_TOKEN: ${{ github.token }} | |
| run: | | |
| if (-not (Test-Path review_comment.md)) { | |
| Write-Error "review_comment.md does not exist - cannot post comment" | |
| exit 1 | |
| } | |
| $pr = "${{ github.event.pull_request.number }}" | |
| # Try to edit last comment; if it fails, create a new one. | |
| gh pr comment $pr --edit-last --body-file review_comment.md | |
| if ($LASTEXITCODE -ne 0) { | |
| Write-Host "Edit-last failed, creating a new comment." | |
| gh pr comment $pr --body-file review_comment.md | |
| if ($LASTEXITCODE -ne 0) { | |
| Write-Error "Failed to post comment to PR" | |
| exit 1 | |
| } | |
| } | |
| Write-Host "Comment posted successfully" |