diff --git a/.github/workflows/claude-code-review.yml b/.github/workflows/claude-code-review.yml index 0538ccfe7..04795bc18 100644 --- a/.github/workflows/claude-code-review.yml +++ b/.github/workflows/claude-code-review.yml @@ -85,14 +85,17 @@ jobs: # for fork PRs. Create a temporary branch ref via the API so the action # can find it. Using the API (not git push) avoids the GITHUB_TOKEN # restriction that blocks pushing commits containing workflow file changes. + # Use a prefixed temporary branch name to avoid overwriting real branches + # (e.g. a fork branch named "main" would overwrite origin/main). - name: Create fork branch ref on origin id: push-fork if: steps.pr.outputs.is_fork == 'true' env: - FORK_BRANCH: ${{ steps.pr.outputs.branch }} + FORK_BRANCH: claude-tmp/fork-pr-${{ steps.pr.outputs.number }} FORK_SHA: ${{ steps.pr.outputs.sha }} GH_TOKEN: ${{ github.token }} run: | + echo "FORK_BRANCH=$FORK_BRANCH" >> "$GITHUB_ENV" gh api "repos/${{ github.repository }}/git/refs" \ --method POST \ -f ref="refs/heads/$FORK_BRANCH" \ @@ -116,6 +119,5 @@ jobs: - name: Delete fork branch ref from origin if: always() && steps.push-fork.outcome == 'success' env: - FORK_BRANCH: ${{ steps.pr.outputs.branch }} GH_TOKEN: ${{ github.token }} run: gh api "repos/${{ github.repository }}/git/refs/heads/$FORK_BRANCH" --method DELETE || true diff --git a/.github/workflows/claude.yml b/.github/workflows/claude.yml index 0f6d008c1..12fc0ccaa 100644 --- a/.github/workflows/claude.yml +++ b/.github/workflows/claude.yml @@ -64,6 +64,7 @@ jobs: const isFork = pr.head.repo.full_name !== pr.base.repo.full_name; core.setOutput('is_pr', 'true'); + core.setOutput('number', String(prNumber)); core.setOutput('is_fork', String(isFork)); core.setOutput('branch', pr.head.ref); core.setOutput('sha', pr.head.sha); @@ -78,14 +79,17 @@ jobs: # for fork PRs. Create a temporary branch ref via the API so the action # can find it. Using the API (not git push) avoids the GITHUB_TOKEN # restriction that blocks pushing commits containing workflow file changes. + # Use a prefixed temporary branch name to avoid overwriting real branches + # (e.g. a fork branch named "main" would overwrite origin/main). - name: Create fork branch ref on origin id: push-fork if: steps.pr.outputs.is_fork == 'true' env: - FORK_BRANCH: ${{ steps.pr.outputs.branch }} + FORK_BRANCH: claude-tmp/fork-pr-${{ steps.pr.outputs.number }} FORK_SHA: ${{ steps.pr.outputs.sha }} GH_TOKEN: ${{ github.token }} run: | + echo "FORK_BRANCH=$FORK_BRANCH" >> "$GITHUB_ENV" gh api "repos/${{ github.repository }}/git/refs" \ --method POST \ -f ref="refs/heads/$FORK_BRANCH" \ @@ -110,6 +114,5 @@ jobs: - name: Delete fork branch ref from origin if: always() && steps.push-fork.outcome == 'success' env: - FORK_BRANCH: ${{ steps.pr.outputs.branch }} GH_TOKEN: ${{ github.token }} run: gh api "repos/${{ github.repository }}/git/refs/heads/$FORK_BRANCH" --method DELETE || true