@@ -29,14 +29,15 @@ function setup_github_authentication(; auto_login::Bool = true)
29
29
30
30
# First check if already authenticated
31
31
try
32
- # Suppress output of gh auth status check
33
- if success (pipeline (` $gh_cmd auth status` ; stdout = devnull , stderr = devnull ))
34
- # Check if logged in to github.com
35
- auth_status_output = read (` $gh_cmd auth status` , String)
36
- if contains (auth_status_output, " Logged in to github.com" )
37
- println (" ✅ Found active `gh` CLI session. Will use it for upload." )
38
- return (:gh_cli , " GitHub CLI" )
39
- end
32
+ # gh auth status outputs to stderr, not stdout
33
+ io = IOBuffer ()
34
+ run (pipeline (` $gh_cmd auth status` ; stderr = io, stdout = devnull ))
35
+ seekstart (io)
36
+ auth_status_output = read (io, String)
37
+
38
+ if contains (auth_status_output, " Logged in to github.com" )
39
+ println (" ✅ Found active `gh` CLI session. Will use it for upload." )
40
+ return (:gh_cli , " GitHub CLI" )
40
41
end
41
42
catch e
42
43
@debug " gh CLI auth status check failed: $e "
@@ -64,21 +65,66 @@ function setup_github_authentication(; auto_login::Bool = true)
64
65
println (" This will open your browser to authenticate with GitHub." )
65
66
println (" Please follow the prompts to complete authentication.\n " )
66
67
68
+ # Run gh auth login - it may fail to open browser but still succeed
69
+ auth_login_success = false
67
70
try
68
- # Run gh auth login interactively (using system gh or JLL)
69
71
run (` $gh_cmd auth login` )
72
+ auth_login_success = true
73
+ catch e
74
+ # gh auth login might fail (e.g., can't open browser) but auth might still work
75
+ println (" \n ⚠️ gh auth login reported an issue: $e " )
76
+ println (" Checking if authentication succeeded anyway..." )
77
+ end
78
+
79
+ # Always check auth status, even if gh auth login appeared to fail
80
+ # This handles cases where browser opening failed but user completed auth manually
81
+ try
82
+ # Small delay to ensure auth is fully processed
83
+ sleep (0.5 )
70
84
71
- # Check if authentication succeeded
72
- if success (pipeline (` $gh_cmd auth status` ; stdout = devnull , stderr = devnull ))
73
- auth_status_output = read (` $gh_cmd auth status` , String)
74
- if contains (auth_status_output, " Logged in to github.com" )
75
- println (" \n ✅ Authentication successful! You can now share results." )
76
- return (:gh_cli , " GitHub CLI" )
85
+ # Check current authentication status
86
+ auth_status_output = " "
87
+ try
88
+ # gh auth status outputs to stderr, not stdout
89
+ io = IOBuffer ()
90
+ run (pipeline (` $gh_cmd auth status` ; stderr = io, stdout = devnull ))
91
+ seekstart (io)
92
+ auth_status_output = read (io, String)
93
+ catch
94
+ # If that fails, try capturing both streams
95
+ try
96
+ io = IOBuffer ()
97
+ run (pipeline (` $gh_cmd auth status` ; stderr = io, stdout = io))
98
+ seekstart (io)
99
+ auth_status_output = read (io, String)
100
+ catch
101
+ # Last resort - assume failure
102
+ auth_status_output = " "
77
103
end
78
104
end
105
+
106
+ if contains (auth_status_output, " Logged in to github.com" )
107
+ println (" \n ✅ Authentication successful! You can now share results." )
108
+ return (:gh_cli , " GitHub CLI" )
109
+ elseif auth_login_success
110
+ # gh auth login succeeded but we can't verify the status
111
+ println (" \n ⚠️ Authentication may have succeeded but couldn't verify status." )
112
+ println (" Attempting to use gh CLI anyway..." )
113
+ return (:gh_cli , " GitHub CLI" )
114
+ else
115
+ println (" \n ❌ Authentication verification failed." )
116
+ println (" Output: " , auth_status_output)
117
+ end
79
118
catch e
80
- println (" \n ❌ Authentication failed: $e " )
81
- println (" You can try again later or use a GitHub token instead." )
119
+ if auth_login_success
120
+ # gh auth login succeeded but status check failed - try anyway
121
+ println (" \n ⚠️ Couldn't verify authentication status: $e " )
122
+ println (" gh auth login appeared successful, attempting to proceed..." )
123
+ return (:gh_cli , " GitHub CLI" )
124
+ else
125
+ println (" \n ❌ Authentication failed: $e " )
126
+ println (" You can try again later or use a GitHub token instead." )
127
+ end
82
128
end
83
129
else
84
130
println (" \n 📝 Skipping authentication. You can authenticate later by:" )
0 commit comments