Skip to content

Commit fece08a

Browse files
yiyixuxuclaude
andauthored
[CI] claude_review: target source PR's branch for follow-up PRs (#13774)
* [CI] claude_review: target source PR's branch for follow-up PRs The follow-up PR was always cut from main, so once main moved on from the PR's base the cherry-pick conflicted and the run failed (see run 26191835696). For non-fork PRs we now target the PR's own head branch instead — Claude's edits apply cleanly regardless of how main has diverged, and merging the follow-up folds them into the original PR. Fork PRs still target the default branch since we can't push to a fork. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com> * [CI] claude_review: skip COMMIT THIS on fork PRs Falling back to main as the base for fork PRs hits the same cherry-pick conflict pattern the previous commit fixed for source PRs, and we can't push to the fork's branch anyway. Bail early with a friendly comment pointing users to apply Claude's suggestions manually or open an issue. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent 6a65a37 commit fece08a

1 file changed

Lines changed: 21 additions & 12 deletions

File tree

.github/workflows/claude_review.yml

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,6 @@ jobs:
156156
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
157157
PR_NUMBER: ${{ github.event.issue.number || github.event.pull_request.number }}
158158
COMMENT_USER: ${{ github.event.comment.user.login }}
159-
BASE_BRANCH: ${{ github.event.repository.default_branch }}
160159
run: |
161160
set -euo pipefail
162161
@@ -186,11 +185,18 @@ jobs:
186185
exit 0
187186
fi
188187
189-
# For fork PRs, an earlier step redirected `origin` to a local bare
190-
# repo to sandbox claude-code-action. Undo that redirect so our push
191-
# reaches the real base repo. Safe: only Claude's edits within the
192-
# allowed paths are committed below — never the fork's other changes.
193-
git config --unset-all url."file:///tmp/local-origin.git".insteadOf 2>/dev/null || true
188+
PR_INFO=$(gh pr view "$PR_NUMBER" --json headRefName,isCrossRepository)
189+
PR_BRANCH=$(echo "$PR_INFO" | jq -r '.headRefName')
190+
IS_FORK=$(echo "$PR_INFO" | jq -r '.isCrossRepository')
191+
192+
# COMMIT THIS isn't supported on fork PRs: we can't push to the
193+
# fork's branch, and falling back to main almost always conflicts
194+
# once the PR touches files that also moved on main. Bail early —
195+
# Claude's review comment with the suggested diff still stands.
196+
if [[ "$IS_FORK" == "true" ]]; then
197+
post_status "ℹ️ \`COMMIT THIS\` isn't supported on fork PRs. Apply Claude's suggestions manually, or open an issue to track them. See [workflow run]($RUN_URL)."
198+
exit 0
199+
fi
194200
195201
git config user.name "claude[bot]"
196202
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
@@ -208,8 +214,6 @@ jobs:
208214
exit 1
209215
fi
210216
211-
PR_BRANCH=$(gh pr view "$PR_NUMBER" --json headRefName --jq '.headRefName')
212-
213217
if [[ "$PR_BRANCH" == claude/pr-* ]]; then
214218
# Source PR is already a Claude-opened PR — iterate in place by
215219
# committing and pushing straight to its head branch instead of
@@ -222,9 +226,14 @@ jobs:
222226
exit 0
223227
fi
224228
225-
# Otherwise: commit on the source PR's branch to get a clean SHA,
226-
# then cherry-pick onto a fresh branch cut from the default branch.
227-
# The follow-up PR's diff is therefore exactly Claude's edits vs. main.
229+
# Target the source PR's head branch. The follow-up then applies
230+
# cleanly regardless of how main has diverged, and merging it lands
231+
# Claude's edits onto the PR for the maintainer to fold in.
232+
BASE_BRANCH="$PR_BRANCH"
233+
234+
# Commit on the source PR's branch to get a clean SHA, then
235+
# cherry-pick onto a fresh branch cut from BASE_BRANCH so the
236+
# follow-up PR's diff is exactly Claude's edits vs. BASE_BRANCH.
228237
NEW_BRANCH="claude/pr-${PR_NUMBER}-$(date -u +%Y%m%d-%H%M%S)"
229238
230239
git commit -m "Apply changes from Claude (requested by @${COMMENT_USER} on #${PR_NUMBER})
@@ -248,6 +257,6 @@ jobs:
248257
--title "Apply Claude's changes from #${PR_NUMBER}" \
249258
--body "Automated PR with edits Claude made in response to \`COMMIT THIS\` from @${COMMENT_USER} on [#${PR_NUMBER}](${GITHUB_SERVER_URL}/${GITHUB_REPOSITORY}/pull/${PR_NUMBER}).
250259
251-
Targets \`${BASE_BRANCH}\` — independent of #${PR_NUMBER}. Further \`COMMIT THIS\` requests on *this* PR will commit directly to it.")
260+
Targets \`${BASE_BRANCH}\` (the head branch of #${PR_NUMBER}). Merging this brings Claude's edits into that PR.")
252261
253262
post_status "✅ Opened follow-up PR (into \`${BASE_BRANCH}\`) with Claude's edits: ${NEW_PR_URL}"

0 commit comments

Comments
 (0)