Skip to content

Commit 82cd1b3

Browse files
Fix PR creation to fork repository first
- Always create/update fork before attempting PR creation - Add proper fork creation with error handling - Get base SHA from fork or fallback to target repository - Add detailed logging for fork creation process - Ensure fork is ready before proceeding with branch creation - Fixes the "you forgot to make a fork first" issue 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]>
1 parent 6e22e62 commit 82cd1b3

File tree

1 file changed

+30
-9
lines changed

1 file changed

+30
-9
lines changed

lib/LinearSolveAutotune/src/telemetry.jl

Lines changed: 30 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -569,24 +569,45 @@ function create_results_pr(target_repo, fallback_repo, branch_name, folder_name,
569569
user = GitHub.whoami(auth=auth)
570570
source_repo = user.login * "/" * repo_name
571571

572-
# Try to get or create a fork
572+
# First, check if we need to create the target repository
573+
if actual_target_repo == fallback_repo
574+
@info "📋 Target repository doesn't exist, using fallback: $actual_target_repo"
575+
end
576+
577+
# Always try to create a fork first (this ensures we have a fork to work with)
573578
fork_repo_obj = nothing
574579
try
575-
fork_repo_obj = GitHub.repo(source_repo, auth=auth)
576-
@info "📋 Using existing fork: $source_repo"
577-
catch
578-
@info "📋 Creating fork of $target_repo..."
580+
@info "📋 Creating/updating fork of $actual_target_repo..."
579581
fork_repo_obj = GitHub.fork(target_repo_obj, auth=auth)
582+
@info "✅ Fork created/updated: $(user.login)/$repo_name"
580583
# Wait a moment for fork to be ready
581-
sleep(2)
584+
sleep(3)
585+
catch e
586+
@info "📋 Fork may already exist, trying to access existing fork..."
587+
try
588+
fork_repo_obj = GitHub.repo(source_repo, auth=auth)
589+
@info "✅ Using existing fork: $source_repo"
590+
catch e2
591+
error("Failed to create or access fork: $e2")
592+
end
582593
end
583594

584595
# Get the default branch (usually main)
585596
default_branch = target_repo_obj.default_branch
597+
@info "📋 Default branch: $default_branch"
586598

587-
# Get the SHA of the default branch
588-
main_branch_ref = GitHub.reference(fork_repo_obj, "heads/$default_branch", auth=auth)
589-
base_sha = main_branch_ref.object["sha"]
599+
# Get the SHA of the default branch from the fork
600+
try
601+
main_branch_ref = GitHub.reference(fork_repo_obj, "heads/$default_branch", auth=auth)
602+
base_sha = main_branch_ref.object["sha"]
603+
@info "📋 Base SHA: $base_sha"
604+
catch e
605+
# If the fork doesn't have the branch yet, get it from the target
606+
@info "📋 Getting base SHA from target repository..."
607+
main_branch_ref = GitHub.reference(target_repo_obj, "heads/$default_branch", auth=auth)
608+
base_sha = main_branch_ref.object["sha"]
609+
@info "📋 Base SHA from target: $base_sha"
610+
end
590611

591612
# Create new branch
592613
try

0 commit comments

Comments
 (0)