mirror of
https://github.com/huggingface/diffusers.git
synced 2026-10-23 09:09:01 +03:00
[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>
This commit is contained in:
33
.github/workflows/claude_review.yml
vendored
33
.github/workflows/claude_review.yml
vendored
@@ -156,7 +156,6 @@ jobs:
|
||||
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
PR_NUMBER: ${{ github.event.issue.number || github.event.pull_request.number }}
|
||||
COMMENT_USER: ${{ github.event.comment.user.login }}
|
||||
BASE_BRANCH: ${{ github.event.repository.default_branch }}
|
||||
run: |
|
||||
set -euo pipefail
|
||||
|
||||
@@ -186,11 +185,18 @@ jobs:
|
||||
exit 0
|
||||
fi
|
||||
|
||||
# For fork PRs, an earlier step redirected `origin` to a local bare
|
||||
# repo to sandbox claude-code-action. Undo that redirect so our push
|
||||
# reaches the real base repo. Safe: only Claude's edits within the
|
||||
# allowed paths are committed below — never the fork's other changes.
|
||||
git config --unset-all url."file:///tmp/local-origin.git".insteadOf 2>/dev/null || true
|
||||
PR_INFO=$(gh pr view "$PR_NUMBER" --json headRefName,isCrossRepository)
|
||||
PR_BRANCH=$(echo "$PR_INFO" | jq -r '.headRefName')
|
||||
IS_FORK=$(echo "$PR_INFO" | jq -r '.isCrossRepository')
|
||||
|
||||
# COMMIT THIS isn't supported on fork PRs: we can't push to the
|
||||
# fork's branch, and falling back to main almost always conflicts
|
||||
# once the PR touches files that also moved on main. Bail early —
|
||||
# Claude's review comment with the suggested diff still stands.
|
||||
if [[ "$IS_FORK" == "true" ]]; then
|
||||
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)."
|
||||
exit 0
|
||||
fi
|
||||
|
||||
git config user.name "claude[bot]"
|
||||
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
|
||||
@@ -208,8 +214,6 @@ jobs:
|
||||
exit 1
|
||||
fi
|
||||
|
||||
PR_BRANCH=$(gh pr view "$PR_NUMBER" --json headRefName --jq '.headRefName')
|
||||
|
||||
if [[ "$PR_BRANCH" == claude/pr-* ]]; then
|
||||
# Source PR is already a Claude-opened PR — iterate in place by
|
||||
# committing and pushing straight to its head branch instead of
|
||||
@@ -222,9 +226,14 @@ jobs:
|
||||
exit 0
|
||||
fi
|
||||
|
||||
# Otherwise: commit on the source PR's branch to get a clean SHA,
|
||||
# then cherry-pick onto a fresh branch cut from the default branch.
|
||||
# The follow-up PR's diff is therefore exactly Claude's edits vs. main.
|
||||
# Target the source PR's head branch. The follow-up then applies
|
||||
# cleanly regardless of how main has diverged, and merging it lands
|
||||
# Claude's edits onto the PR for the maintainer to fold in.
|
||||
BASE_BRANCH="$PR_BRANCH"
|
||||
|
||||
# Commit on the source PR's branch to get a clean SHA, then
|
||||
# cherry-pick onto a fresh branch cut from BASE_BRANCH so the
|
||||
# follow-up PR's diff is exactly Claude's edits vs. BASE_BRANCH.
|
||||
NEW_BRANCH="claude/pr-${PR_NUMBER}-$(date -u +%Y%m%d-%H%M%S)"
|
||||
|
||||
git commit -m "Apply changes from Claude (requested by @${COMMENT_USER} on #${PR_NUMBER})
|
||||
@@ -248,6 +257,6 @@ jobs:
|
||||
--title "Apply Claude's changes from #${PR_NUMBER}" \
|
||||
--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}).
|
||||
|
||||
Targets \`${BASE_BRANCH}\` — independent of #${PR_NUMBER}. Further \`COMMIT THIS\` requests on *this* PR will commit directly to it.")
|
||||
Targets \`${BASE_BRANCH}\` (the head branch of #${PR_NUMBER}). Merging this brings Claude's edits into that PR.")
|
||||
|
||||
post_status "✅ Opened follow-up PR (into \`${BASE_BRANCH}\`) with Claude's edits: ${NEW_PR_URL}"
|
||||
|
||||
Reference in New Issue
Block a user