Skip to content

Commit baa3b1d

Browse files
Implement real pull request creation for benchmark results
Replace stub PR creation function with full implementation that: - Creates/uses fork of target repository - Creates feature branch with unique name - Uploads all result files (CSV, PNG, README, Project.toml) - Creates proper pull request with detailed description - Handles existing branches and files gracefully The previous implementation was just returning a fake URL to issue #1 instead of actually creating a pull request. Now it will create real PRs to SciML/LinearSolveAutotuneResults.jl with the benchmark data. Fixes fake PR creation that was actually just logging a fake URL 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]>
1 parent 24f9387 commit baa3b1d

File tree

1 file changed

+126
-6
lines changed

1 file changed

+126
-6
lines changed

lib/LinearSolveAutotune/src/telemetry.jl

Lines changed: 126 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -531,14 +531,134 @@ Create a pull request with the benchmark results.
531531
"""
532532
function create_results_pr(target_repo, branch_name, folder_name, files, auth)
533533
try
534-
# This is a simplified implementation - full PR creation is complex
535-
# For now, let's just create a basic structure
536-
@info "🚧 PR creation functionality is under development"
537-
@info "📋 Would create PR with folder: $folder_name"
534+
@info "🚧 Creating pull request with benchmark results..."
535+
@info "📋 Target: $target_repo, Branch: $branch_name"
538536
@info "📋 Files to include: $(length(files)) files"
539537

540-
# Return a mock result to indicate success
541-
return Dict("html_url" => "https://github.com/$target_repo/pull/1")
538+
# Split the target repo name
539+
repo_parts = split(target_repo, "/")
540+
if length(repo_parts) != 2
541+
error("Invalid repository format: $target_repo")
542+
end
543+
repo_owner, repo_name = repo_parts
544+
545+
# Get the target repository
546+
target_repo_obj = GitHub.repo(repo_owner * "/" * repo_name, auth=auth)
547+
548+
# Get authenticated user to determine source repo
549+
user = GitHub.whoami(auth=auth)
550+
source_repo = user.login * "/" * repo_name
551+
552+
# Try to get or create a fork
553+
fork_repo_obj = nothing
554+
try
555+
fork_repo_obj = GitHub.repo(source_repo, auth=auth)
556+
@info "📋 Using existing fork: $source_repo"
557+
catch
558+
@info "📋 Creating fork of $target_repo..."
559+
fork_repo_obj = GitHub.fork(target_repo_obj, auth=auth)
560+
# Wait a moment for fork to be ready
561+
sleep(2)
562+
end
563+
564+
# Get the default branch (usually main)
565+
default_branch = target_repo_obj.default_branch
566+
567+
# Get the SHA of the default branch
568+
main_branch_ref = GitHub.reference(fork_repo_obj, "heads/$default_branch", auth=auth)
569+
base_sha = main_branch_ref.object["sha"]
570+
571+
# Create new branch
572+
try
573+
GitHub.create_ref(fork_repo_obj, "refs/heads/$branch_name", base_sha, auth=auth)
574+
@info "📋 Created new branch: $branch_name"
575+
catch e
576+
if contains(string(e), "Reference already exists")
577+
@info "📋 Branch $branch_name already exists, updating..."
578+
# Update existing branch to point to main
579+
GitHub.update_ref(fork_repo_obj, "heads/$branch_name", base_sha, auth=auth)
580+
else
581+
rethrow(e)
582+
end
583+
end
584+
585+
# Create all files in the repository
586+
for (file_path, file_content) in files
587+
try
588+
# Try to get existing file to update it
589+
existing_file = nothing
590+
try
591+
existing_file = GitHub.file(fork_repo_obj, file_path, ref=branch_name, auth=auth)
592+
catch
593+
# File doesn't exist, that's fine
594+
end
595+
596+
commit_message = if existing_file === nothing
597+
"Add $(basename(file_path)) for $folder_name"
598+
else
599+
"Update $(basename(file_path)) for $folder_name"
600+
end
601+
602+
# Create or update the file
603+
if isa(file_content, String)
604+
# Text content
605+
GitHub.create_file(fork_repo_obj, file_path,
606+
message=commit_message,
607+
content=file_content,
608+
branch=branch_name,
609+
sha=existing_file === nothing ? nothing : existing_file.sha,
610+
auth=auth)
611+
else
612+
# Binary content (already base64 encoded)
613+
GitHub.create_file(fork_repo_obj, file_path,
614+
message=commit_message,
615+
content=file_content,
616+
branch=branch_name,
617+
sha=existing_file === nothing ? nothing : existing_file.sha,
618+
auth=auth)
619+
end
620+
621+
@info "📋 Created/updated: $file_path"
622+
catch e
623+
@warn "Failed to create file $file_path: $e"
624+
end
625+
end
626+
627+
# Create pull request
628+
pr_title = "Add benchmark results: $folder_name"
629+
pr_body = """
630+
# LinearSolve.jl Benchmark Results
631+
632+
Automated submission of benchmark results from the LinearSolve.jl autotune system.
633+
634+
## System Information
635+
- **Folder**: `results/$folder_name`
636+
- **Files**: $(length(files)) files including CSV data, plots, and system info
637+
- **Timestamp**: $(Dates.now())
638+
639+
## Contents
640+
- `results.csv` - Detailed benchmark performance data
641+
- `system_info.csv` - System and hardware configuration
642+
- `Project.toml` - Package versions used
643+
- `README.md` - Human-readable summary
644+
- `*.png` - Performance visualization plots
645+
646+
## Automated Submission
647+
This PR was automatically created by the LinearSolve.jl autotune system.
648+
The benchmark data will help improve algorithm selection for the community.
649+
650+
🤖 Generated by LinearSolve.jl autotune system
651+
"""
652+
653+
pr_result = GitHub.create_pull_request(target_repo_obj,
654+
title=pr_title,
655+
body=pr_body,
656+
head="$(user.login):$branch_name",
657+
base=default_branch,
658+
auth=auth)
659+
660+
@info "✅ Successfully created pull request #$(pr_result.number)"
661+
return pr_result
542662

543663
catch e
544664
@warn "Failed to create pull request: $e"

0 commit comments

Comments
 (0)