Skip to content

Commit f244cf8

Browse files
committed
fix claude to work with forks
1 parent 74d29ef commit f244cf8

1 file changed

Lines changed: 22 additions & 4 deletions

File tree

.github/workflows/claude.yml

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -260,16 +260,34 @@ jobs:
260260
run: |
261261
PR_NUMBER=${{ github.event.issue.number }}
262262
263-
# Get PR details
264-
PR_DATA=$(gh pr view $PR_NUMBER --json headRefOid,baseRefName,headRefName)
263+
# Get PR details including fork info
264+
PR_DATA=$(gh pr view $PR_NUMBER --json headRefOid,baseRefName,headRefName,headRepository,headRepositoryOwner)
265265
PR_HEAD_SHA=$(echo "$PR_DATA" | jq -r '.headRefOid')
266266
BASE_BRANCH=$(echo "$PR_DATA" | jq -r '.baseRefName')
267+
HEAD_REPO_OWNER=$(echo "$PR_DATA" | jq -r '.headRepositoryOwner.login')
268+
HEAD_REPO_NAME=$(echo "$PR_DATA" | jq -r '.headRepository.name')
267269
268270
echo "PR #$PR_NUMBER: $BASE_BRANCH...$PR_HEAD_SHA"
271+
echo "Head repo: $HEAD_REPO_OWNER/$HEAD_REPO_NAME"
269272
270-
# Fetch and checkout PR head
271-
git fetch origin $PR_HEAD_SHA
273+
# Fetch base branch from origin
272274
git fetch origin $BASE_BRANCH
275+
276+
# For fork PRs, add fork as remote and fetch from it
277+
if [ "$HEAD_REPO_OWNER" != "${{ github.repository_owner }}" ]; then
278+
echo "Fork PR detected, fetching from fork repository"
279+
# Remove fork remote if it already exists from a previous run
280+
git remote remove fork 2>/dev/null || true
281+
git remote add fork https://github.com/$HEAD_REPO_OWNER/$HEAD_REPO_NAME.git
282+
git fetch fork $PR_HEAD_SHA || {
283+
echo "Failed to fetch from fork. Fork may be private or deleted."
284+
exit 1
285+
}
286+
else
287+
echo "Non-fork PR, fetching from origin"
288+
git fetch origin $PR_HEAD_SHA
289+
fi
290+
273291
git checkout $PR_HEAD_SHA
274292
275293
# Generate diff in repo root (where Claude has access)

0 commit comments

Comments
 (0)