Skip to content

Commit 44492a5

Browse files
Fix GitHub token permissions and add issue fallback
- Update token setup instructions to include required permissions - Add 'Contents: Read and write', 'Pull requests: Write', 'Forks: Write' - Provide specific error guidance for 403 permission errors - Add fallback to create GitHub issue when PR creation fails - Better user experience when token lacks fork creation permissions - Ensures benchmark data can still be shared even with limited tokens 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]>
1 parent 9fdefca commit 44492a5

File tree

1 file changed

+81
-1
lines changed

1 file changed

+81
-1
lines changed

lib/LinearSolveAutotune/src/telemetry.jl

Lines changed: 81 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ function setup_github_authentication()
3030
println(" • Name: 'LinearSolve Autotune'")
3131
println(" • Expiration: 90 days")
3232
println(" • Repository access: 'Public Repositories (read-only)'")
33+
println(" • Permissions: Enable 'Contents: Read and write', 'Pull requests: Write', 'Forks: Write'")
3334
println("4️⃣ Click 'Generate token' and copy it")
3435
println()
3536
println("🔑 Paste your GitHub token here:")
@@ -401,6 +402,22 @@ function upload_to_github(content::String, plot_files::Union{Nothing, Tuple, Dic
401402

402403
catch e
403404
@warn "❌ Failed to create pull request: $e"
405+
406+
# Try creating an issue as fallback if it's a permissions issue
407+
if contains(string(e), "403") || contains(string(e), "permissions") || contains(string(e), "fork")
408+
@info "💡 Attempting to create issue instead of PR due to permissions..."
409+
try
410+
issue_result = create_benchmark_issue(target_repo, fallback_repo, content, auth, system_info)
411+
if issue_result !== nothing
412+
@info "✅ Created benchmark results issue: $(issue_result["html_url"])"
413+
@info "🔗 Your benchmark data has been shared with the community!"
414+
return
415+
end
416+
catch issue_error
417+
@info "💡 Could not create issue either: $issue_error"
418+
end
419+
end
420+
404421
@info "💡 This could be due to network issues, repository permissions, or API limits."
405422

406423
# Save locally as fallback
@@ -411,6 +428,62 @@ function upload_to_github(content::String, plot_files::Union{Nothing, Tuple, Dic
411428
end
412429
end
413430

431+
"""
432+
create_benchmark_issue(target_repo, fallback_repo, content, auth, system_info)
433+
434+
Create a GitHub issue with benchmark results as a fallback when PR creation fails.
435+
"""
436+
function create_benchmark_issue(target_repo, fallback_repo, content, auth, system_info)
437+
try
438+
# Try target repository first, fallback if needed
439+
actual_repo = target_repo
440+
repo_obj = nothing
441+
442+
try
443+
repo_obj = GitHub.repo(target_repo, auth=auth)
444+
catch
445+
@info "📋 Using fallback repository for issue: $fallback_repo"
446+
actual_repo = fallback_repo
447+
repo_obj = GitHub.repo(fallback_repo, auth=auth)
448+
end
449+
450+
# Create issue title and body
451+
cpu_name = get(system_info, "cpu_name", "unknown")
452+
os_name = get(system_info, "os", "unknown")
453+
timestamp = Dates.format(Dates.now(), "yyyy-mm-dd HH:MM")
454+
455+
issue_title = "Benchmark Results: $cpu_name on $os_name ($timestamp)"
456+
457+
issue_body = """
458+
# LinearSolve.jl Autotune Benchmark Results
459+
460+
**Submitted via GitHub Issue** (PR creation failed due to token permissions)
461+
462+
$content
463+
464+
---
465+
466+
**Note**: This was submitted as an issue because the GitHub token lacks fork creation permissions.
467+
To enable PR creation, please create a token with 'Contents: Read and write', 'Pull requests: Write', and 'Forks: Write' permissions.
468+
469+
🤖 *Generated automatically by LinearSolve.jl autotune system*
470+
"""
471+
472+
# Create the issue
473+
issue_result = GitHub.create_issue(repo_obj,
474+
title=issue_title,
475+
body=issue_body,
476+
auth=auth)
477+
478+
@info "✅ Created benchmark results issue #$(issue_result.number)"
479+
return issue_result
480+
481+
catch e
482+
@warn "Failed to create benchmark issue: $e"
483+
return nothing
484+
end
485+
end
486+
414487
"""
415488
create_result_files(folder_name, content, plot_files, results_df, system_info, categories)
416489
@@ -598,7 +671,14 @@ function create_results_pr(target_repo, fallback_repo, branch_name, folder_name,
598671
error("Failed to access existing fork: $e2")
599672
end
600673
else
601-
error("Failed to create fork: $e")
674+
if contains(string(e), "403") && contains(string(e), "Resource not accessible by personal access token")
675+
@warn "GitHub token lacks fork creation permissions. Please create a new token with 'Forks: Write' permission."
676+
@info "📋 Token setup guide: Go to https://github.com/settings/tokens?type=beta"
677+
@info "📋 Enable permissions: 'Contents: Read and write', 'Pull requests: Write', 'Forks: Write'"
678+
error("GitHub token permissions insufficient for fork creation")
679+
else
680+
error("Failed to create fork: $e")
681+
end
602682
end
603683
end
604684

0 commit comments

Comments
 (0)