Skip to content

Modify CLAUDE code review workflow for PR handling#1354

Merged
sbryngelson merged 3 commits intomasterfrom
claude-reviewer
Apr 5, 2026
Merged

Modify CLAUDE code review workflow for PR handling#1354
sbryngelson merged 3 commits intomasterfrom
claude-reviewer

Conversation

@sbryngelson
Copy link
Copy Markdown
Member

fix claude reviewer

Updated the workflow to fetch the PR branch and adjusted checkout depth.
@github-actions
Copy link
Copy Markdown

github-actions bot commented Apr 4, 2026

Claude Code Review

Head SHA: 1ced066

Files changed:

  • 1
  • .github/workflows/claude-code-review.yml

Findings:

Fork PR support broken by git fetch origin "$PR_HEAD_REF"

The new "Fetch PR branch" step runs:

git fetch origin "$PR_HEAD_REF"

For PRs opened from forks, PR_HEAD_REF is the branch name as it exists in the contributor's fork — not in origin. git fetch origin will fail with fatal: couldn't find remote ref <branch>, and because the step runs under set -euo pipefail, the entire job fails, blocking the review for all fork-sourced PRs.

The correct ref to fetch for any PR (including forks) is the GitHub-managed pull request ref: refs/pull/$PR_NUMBER/head. For example:

git fetch origin "refs/pull/${{ steps.mode.outputs.pr_number }}/head"

This ref is always present in origin regardless of whether the PR comes from the same repo or a fork.

@sbryngelson sbryngelson closed this Apr 4, 2026
@sbryngelson sbryngelson reopened this Apr 4, 2026
@sbryngelson
Copy link
Copy Markdown
Member Author

@claude full review

@claude
Copy link
Copy Markdown

claude bot commented Apr 4, 2026

Claude Code is working…

I'll analyze this and get back to you.

View job run

@sbryngelson sbryngelson added the claude-full-review Trigger Claude Code review label Apr 4, 2026
@sbryngelson sbryngelson marked this pull request as ready for review April 5, 2026 15:22
@sbryngelson sbryngelson merged commit 5190918 into master Apr 5, 2026
49 of 61 checks passed
@sbryngelson sbryngelson deleted the claude-reviewer branch April 5, 2026 15:22
@qodo-code-review
Copy link
Copy Markdown
Contributor

Review Summary by Qodo

Refactor PR checkout and branch fetching workflow

✨ Enhancement 🐞 Bug fix

Grey Divider

Walkthroughs

Description
• Restructured PR checkout workflow to fetch PR branch explicitly
• Added dynamic PR head reference detection using GitHub CLI
• Increased git fetch depth from 1 to 0 for complete history
• Removed positive confirmation guideline from code review instructions
Diagram
flowchart LR
  A["Determine PR number"] --> B["Fetch PR head reference via gh CLI"]
  B --> C["Checkout base repo with full depth"]
  C --> D["Fetch PR branch explicitly"]
  D --> E["Resolve review state"]
  F["Remove positive confirmation guideline"] -.-> E
Loading

Grey Divider

File Changes

1. .github/workflows/claude-code-review.yml ✨ Enhancement +19/-6

Restructure PR branch fetching and checkout logic

• Removed initial checkout step and moved it after PR number determination
• Added GitHub CLI command to dynamically fetch PR head reference name
• Changed git fetch-depth from 1 to 0 for complete repository history
• Added explicit git fetch step for the PR branch using environment variable
• Removed period from positive confirmation guideline in code review instructions

.github/workflows/claude-code-review.yml


Grey Divider

Qodo Logo

@qodo-code-review
Copy link
Copy Markdown
Contributor

qodo-code-review bot commented Apr 5, 2026

Code Review by Qodo

🐞 Bugs (2) 📘 Rule violations (0) 📎 Requirement gaps (0) 🎨 UX Issues (0)

Grey Divider


Action required

1. Fork PR fetch breaks 🐞 Bug ☼ Reliability
Description
The workflow computes PR_HEAD_REF using only headRefName and then runs `git fetch origin
"$PR_HEAD_REF", which only works if the PR head branch exists on the origin` remote (the
checked-out base repo). For PRs where the head branch is not on origin, this step fails under `set
-euo pipefail` and prevents any review from being published.
Code

.github/workflows/claude-code-review.yml[R61-77]

+          PR_HEAD_REF="$(gh pr view "$PR_NUMBER" --repo "${{ github.repository }}" --json headRefName --jq .headRefName)"
+
          echo "pr_number=$PR_NUMBER" >> "$GITHUB_OUTPUT"
+          echo "pr_head_ref=$PR_HEAD_REF" >> "$GITHUB_OUTPUT"
+
+      - name: Checkout base repo
+        uses: actions/checkout@v4
+        with:
+          fetch-depth: 0
+
+      - name: Fetch PR branch
+        shell: bash
+        env:
+          PR_HEAD_REF: ${{ steps.mode.outputs.pr_head_ref }}
+        run: |
+          set -euo pipefail
+          git fetch origin "$PR_HEAD_REF"
Evidence
The workflow runs on pull_request_target and checks out the base repository, making origin point
to the base repo. It then derives PR_HEAD_REF from gh pr view ... --json headRefName and fetches
that name from origin, which is only valid when the PR head branch is actually in the base repo
remote namespace.

.github/workflows/claude-code-review.yml[3-5]
.github/workflows/claude-code-review.yml[61-64]
.github/workflows/claude-code-review.yml[66-77]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

### Issue description
The workflow fetches the PR head branch by name from `origin`, but `origin` is the base repo. This fails when the PR’s head branch is not present on `origin`, causing the job to abort.

### Issue Context
This job runs on `pull_request_target`, checks out the base repo, and then tries to fetch the PR branch.

### Fix Focus Areas
- .github/workflows/claude-code-review.yml[61-77]

### Suggested fix
Prefer fetching the PR head via GitHub’s pull refs (works regardless of fork), e.g. use the PR number:
- Replace the `headRefName`-based fetch with something like:
 - `git fetch origin "refs/pull/$PR_NUMBER/head:refs/remotes/origin/pr/$PR_NUMBER"`
- Or remove the fetch entirely if nothing downstream actually needs local git refs.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools



Remediation recommended

2. Over-fetching git data 🐞 Bug ➹ Performance
Description
The workflow uses fetch-depth: 0 and performs an unbounded git fetch even though the review
inputs are built via gh pr diff and gh api (not via local git history). This unnecessarily
increases runtime/network use and adds avoidable failure points in the review job.
Code

.github/workflows/claude-code-review.yml[R66-77]

+      - name: Checkout base repo
+        uses: actions/checkout@v4
+        with:
+          fetch-depth: 0
+
+      - name: Fetch PR branch
+        shell: bash
+        env:
+          PR_HEAD_REF: ${{ steps.mode.outputs.pr_head_ref }}
+        run: |
+          set -euo pipefail
+          git fetch origin "$PR_HEAD_REF"
Evidence
After checkout/fetch, the workflow’s review inputs are generated using GitHub CLI/API (gh pr diff,
gh api repos/.../contents) rather than local git history operations, so fetching full history and
an unbounded ref is not required for the shown steps.

.github/workflows/claude-code-review.yml[66-77]
.github/workflows/claude-code-review.yml[110-134]
.github/workflows/claude-code-review.yml[140-176]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

### Issue description
The job pulls full git history (`fetch-depth: 0`) and does an unbounded `git fetch`, even though the rest of the workflow uses `gh pr diff` / `gh api` to build inputs.

### Issue Context
This affects job latency and reliability (extra network operations) without clear benefit in the current workflow.

### Fix Focus Areas
- .github/workflows/claude-code-review.yml[66-77]

### Suggested fix
- If local git refs aren’t required, remove the checkout + fetch steps entirely.
- If they are required, make them shallow:
 - set `fetch-depth: 1` (or another minimal value)
 - use `git fetch --depth=1 ...` when fetching the PR ref.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


Grey Divider

ⓘ The new review experience is currently in Beta. Learn more

Grey Divider

Qodo Logo

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Apr 5, 2026

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 91c97dce-81ac-4d9b-b431-66404865b397

📥 Commits

Reviewing files that changed from the base of the PR and between cf81f25 and 1ced066.

📒 Files selected for processing (1)
  • .github/workflows/claude-code-review.yml

📝 Walkthrough

Walkthrough

The .github/workflows/claude-code-review.yml workflow was modified to improve repository fetching and PR head reference handling. Changes include removal of an initial checkout step, introduction of a new step to compute and export the PR head reference name using the GitHub CLI, adjustment of fetch depth from shallow to full for the base repository, and addition of an explicit git fetch for the PR head reference. The GitHub token environment variable was added to support CLI command execution, and punctuation was adjusted in a Claude prompt instruction.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Comment on lines +61 to +77
PR_HEAD_REF="$(gh pr view "$PR_NUMBER" --repo "${{ github.repository }}" --json headRefName --jq .headRefName)"

echo "pr_number=$PR_NUMBER" >> "$GITHUB_OUTPUT"
echo "pr_head_ref=$PR_HEAD_REF" >> "$GITHUB_OUTPUT"

- name: Checkout base repo
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Fetch PR branch
shell: bash
env:
PR_HEAD_REF: ${{ steps.mode.outputs.pr_head_ref }}
run: |
set -euo pipefail
git fetch origin "$PR_HEAD_REF"
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.

Action required

1. Fork pr fetch breaks 🐞 Bug ☼ Reliability

The workflow computes PR_HEAD_REF using only headRefName and then runs `git fetch origin
"$PR_HEAD_REF", which only works if the PR head branch exists on the origin` remote (the
checked-out base repo). For PRs where the head branch is not on origin, this step fails under `set
-euo pipefail` and prevents any review from being published.
Agent Prompt
### Issue description
The workflow fetches the PR head branch by name from `origin`, but `origin` is the base repo. This fails when the PR’s head branch is not present on `origin`, causing the job to abort.

### Issue Context
This job runs on `pull_request_target`, checks out the base repo, and then tries to fetch the PR branch.

### Fix Focus Areas
- .github/workflows/claude-code-review.yml[61-77]

### Suggested fix
Prefer fetching the PR head via GitHub’s pull refs (works regardless of fork), e.g. use the PR number:
- Replace the `headRefName`-based fetch with something like:
  - `git fetch origin "refs/pull/$PR_NUMBER/head:refs/remotes/origin/pr/$PR_NUMBER"`
- Or remove the fetch entirely if nothing downstream actually needs local git refs.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

claude-full-review Trigger Claude Code review

Development

Successfully merging this pull request may close these issues.

2 participants