Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 6 additions & 24 deletions .github/workflows/claude-code-review.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,6 @@
name: Claude Code Review

on:
workflow_dispatch:
inputs:
pr_number:
description: 'PR number to review'
required: true
type: string
pull_request:
types: [opened, synchronize, ready_for_review, reopened]
paths-ignore:
Expand All @@ -23,30 +17,18 @@ permissions:
jobs:
claude-review:
if: |
github.event_name == 'workflow_dispatch' || (
github.actor != 'coderabbitai[bot]' &&
!contains(github.event.pull_request.title, '[skip review]') &&
!contains(github.event.pull_request.labels.*.name, 'skip-review')
)
github.actor != 'coderabbitai[bot]' &&
!contains(github.event.pull_request.title, '[skip review]') &&
!contains(github.event.pull_request.labels.*.name, 'skip-review')
concurrency:
group: claude-review-${{ github.event.pull_request.number || inputs.pr_number }}
group: claude-review-${{ github.event.pull_request.number }}
cancel-in-progress: true
runs-on: ubuntu-latest
steps:
- name: Resolve PR
id: pr
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
PR_NUMBER: ${{ github.event.pull_request.number || inputs.pr_number }}
run: |
HEAD_REF=$(gh pr view "$PR_NUMBER" --repo "${{ github.repository }}" --json headRefName -q .headRefName)
echo "number=$PR_NUMBER" >> "$GITHUB_OUTPUT"
echo "head_ref=$HEAD_REF" >> "$GITHUB_OUTPUT"

- name: Checkout PR head
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6
with:
ref: ${{ steps.pr.outputs.head_ref }}
ref: ${{ github.event.pull_request.head.ref }}
Comment on lines 28 to +31

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major | ⚡ Quick win

🧩 Analysis chain

🌐 Web query:

For actions/checkoutin apull_requestworkflow, what is the recommended configuration to check out the exact PR head commit for both same-repo and fork PRs? Please verify whetherrepository: ${{ github.event.pull_request.head.repo.full_name }}withref: ${{ github.event.pull_request.head.sha }}is preferred over using onlygithub.event.pull_request.head.ref.

💡 Result:

Recommended configuration (pull_request workflow) to check out the exact PR head commit for both same-repo and fork PRs: - uses: actions/checkout@v6 with: repository: ${{ github.event.pull_request.head.repo.full_name }} ref: ${{ github.event.pull_request.head.sha }} This uses the PR head repo’s full_name (so forks work) together with the PR head SHA (so you check out the exact commit, not the default merge ref). Why not rely on github.event.pull_request.head.ref? - The checkout action docs explicitly show checking out the PR head by specifying ref: ${{ github.event.pull_request.head.sha }} (described as “Checkout pull request HEAD commit instead of merge commit”). [1] - In a pull_request-triggered workflow, GitHub Actions checks out the PR merge commit by default (GITHUB_SHA points to the merge commit), so you must override it to get the head commit. [2] - Using only github.event.pull_request.head.ref would select a branch name rather than the exact commit; the docs guidance is to use the head SHA for the head-commit checkout. [1] Is repository: ${{ github.event.pull_request.head.repo.full_name }} with ref: ${{ github.event.pull_request.head.sha }} preferred over only head.ref? - Yes, because it directly checks out the exact head commit (head.sha) and correctly targets the head repository for forks (head.repo.full_name), while head.ref is only a ref name and isn’t the documentation’s recommended mechanism for ensuring the exact head commit checkout. [1][3] Note: actions/checkout also documents that ref input can be a branch, tag, or SHA, and provides an example specifically for pull_request head SHA checkout. [4][1]

Citations:


Check out the exact PR commit, not the mutable branch name.

Line 31 uses github.event.pull_request.head.ref, which is just the source branch name. This fails for fork PRs because checkout still defaults to the base repository, and it reviews/pushes against a newer commit if the branch moves before a rerun. Use the PR head repository plus head.sha to ensure the agent always works on the exact revision that triggered the workflow.

Suggested change
       - name: Checkout PR head
         uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6
         with:
-          ref: ${{ github.event.pull_request.head.ref }}
+          repository: ${{ github.event.pull_request.head.repo.full_name }}
+          ref: ${{ github.event.pull_request.head.sha }}
           fetch-depth: 20
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
- name: Checkout PR head
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6
with:
ref: ${{ steps.pr.outputs.head_ref }}
ref: ${{ github.event.pull_request.head.ref }}
- name: Checkout PR head
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6
with:
repository: ${{ github.event.pull_request.head.repo.full_name }}
ref: ${{ github.event.pull_request.head.sha }}
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In @.github/workflows/claude-code-review.yml around lines 28 - 31, The workflow
is checking out the PR branch by name (uses actions/checkout and ref:
github.event.pull_request.head.ref) which can point to a moving branch and fails
for forked PRs; change the checkout step to fetch the exact PR commit by using
the PR head repository full name and the commit SHA
(github.event.pull_request.head.repo.full_name and
github.event.pull_request.head.sha) so actions/checkout checks out the precise
revision that triggered the workflow.

fetch-depth: 20

- name: Run Claude Code Review (agentic)
Expand All @@ -60,7 +42,7 @@ jobs:
plugins: 'code-review@claude-code-plugins'
claude_args: '--model claude-opus-4-7 --max-turns 25'
prompt: |
/code-review:code-review ${{ github.repository }}/pull/${{ steps.pr.outputs.number }}
/code-review:code-review ${{ github.repository }}/pull/${{ github.event.pull_request.number }}

Operating mode: **agentic**. You have write access to this PR branch.

Expand Down
Loading