Skip to content

chore(api): refactor get last snapshot query #1458

chore(api): refactor get last snapshot query

chore(api): refactor get last snapshot query #1458

name: Claude Code Review
on:
pull_request:
types: [opened]
issue_comment:
types: [created]
jobs:
claude-review:
name: Claude Code Review
runs-on: ubuntu-latest
if: |
github.event_name == 'pull_request' ||
(github.event_name == 'issue_comment' &&
github.event.issue.pull_request != null &&
contains(github.event.comment.body, '@claude review') &&
(github.event.comment.author_association == 'OWNER' ||
github.event.comment.author_association == 'MEMBER' ||
github.event.comment.author_association == 'COLLABORATOR'))
permissions:
contents: read
pull-requests: write
issues: read
id-token: write
steps:
- name: Checkout repository
uses: actions/checkout@v5
with:
fetch-depth: 1
- name: Get PR head SHA
id: pr-sha
run: |
if [ "${{ github.event_name }}" == "pull_request" ]; then
echo "sha=${{ github.event.pull_request.head.sha }}" >> $GITHUB_OUTPUT
else
PR_NUMBER=${{ github.event.issue.number }}
HEAD_SHA=$(gh pr view $PR_NUMBER --json headRefOid -q .headRefOid)
echo "sha=$HEAD_SHA" >> $GITHUB_OUTPUT
fi
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Run Claude Code Review
id: claude-review
uses: anthropics/claude-code-action@v1
with:
anthropic_api_key: ${{ secrets.ANTHROPIC_API_KEY }}
prompt: |
REPO: ${{ github.repository }}
PR NUMBER: ${{ github.event.pull_request.number || github.event.issue.number }}
Please review this pull request and provide feedback on:
- Potential bugs or issues
- Performance considerations
- Important security concerns
Be constructive and helpful in your feedback and be **very concise**.
Skip general recommendations, skip summarizing the changes, and don't make any recommendations on code style.
Also skip any summarization about why the PR was done well, focus only on the code changes and the potential issues.
Don't output final summaries, or final lists of action items.
Reduce false positives—try to validate if the issue is really a valid problem in the changes.
IMPORTANT WORKFLOW:
1. First, analyze ALL files in the diff completely. Do NOT post any comments until you have reviewed everything.
2. Collect every specific issue you find (bug, performance concern, security risk, etc.) with its file path, line number, and description.
3. If no issues are found, do not post anything at all.
4. Once you have collected all issues, post them ALL in a SINGLE GitHub review using the command below.
To post all comments as one review, use this exact format:
```bash
gh api --method POST -H "Accept: application/vnd.github+json" -H "X-GitHub-Api-Version: 2022-11-28" /repos/${{ github.repository }}/pulls/${{ github.event.pull_request.number || github.event.issue.number }}/reviews --input /dev/stdin <<'REVIEW_EOF'
{
"commit_id": "${{ steps.pr-sha.outputs.sha }}",
"event": "COMMENT",
"comments": [
{
"path": "relative/path/to/file.go",
"line": 42,
"side": "RIGHT",
"body": "Description of the issue found."
}
]
}
REVIEW_EOF
```
IMPORTANT:
- The command MUST start with `gh api`
- Use the heredoc syntax shown above with `<<'REVIEW_EOF'` (single-quoted to prevent shell expansion)
- The JSON inside the heredoc must be valid JSON
- The `line` field must be a number, not a string
- Escape double quotes in the body with `\"` and newlines with `\n`
- Include ALL issues as entries in the `comments` array — do NOT make multiple API calls
- Even if you find only one issue, use this same batched review format
claude_args: '--allowed-tools "Bash(gh api:*), Bash(gh issue view:*),Bash(gh search:*),Bash(gh issue list:*),Bash(gh pr comment:*),Bash(gh pr diff:*),Bash(gh pr view:*),Bash(gh pr list:*)"'