@@ -26,7 +26,7 @@ pub async fn codeql_download(action: &Action) -> Result<CodeQL> {
2626
2727 // Try to install with authentication first (if token is available)
2828 if !token. is_empty ( ) {
29- let octocrab_auth = action. octocrab_with_token ( token) ?;
29+ let octocrab_auth = action. octocrab_with_token ( & token) ?;
3030 if let Ok ( _) = codeql. install ( & octocrab_auth, codeql_version) . await {
3131 log:: info!( "CodeQL installed using authentication" ) ;
3232 return Ok ( codeql) ;
@@ -35,6 +35,8 @@ pub async fn codeql_download(action: &Action) -> Result<CodeQL> {
3535 "Failed to install CodeQL with authentication, trying without authentication..."
3636 ) ;
3737 }
38+ } else {
39+ log:: debug!( "No token provided, skipping authenticated installation attempt" ) ;
3840 }
3941
4042 // Try to install without authentication
@@ -47,15 +49,17 @@ pub async fn codeql_download(action: &Action) -> Result<CodeQL> {
4749 log:: info!( "Attempting to install CodeQL using GitHub CLI..." ) ;
4850 }
4951
50- let location = gh_codeql_download ( codeql_version)
51- . await
52- . context ( "Failed to download CodeQL using GitHub CLI" ) ?;
53- // Reinitialize CodeQL with the new path
54- codeql = CodeQL :: init ( )
55- . path ( location)
56- . build ( )
57- . await
58- . context ( "Failed to create CodeQL instance after GitHub CLI installation" ) ?;
52+ if !token. is_empty ( ) {
53+ let location = gh_codeql_download ( codeql_version, & token)
54+ . await
55+ . context ( "Failed to download CodeQL using GitHub CLI" ) ?;
56+ // Reinitialize CodeQL with the new path
57+ codeql = CodeQL :: init ( )
58+ . path ( location)
59+ . build ( )
60+ . await
61+ . context ( "Failed to create CodeQL instance after GitHub CLI installation" ) ?;
62+ }
5963
6064 log:: info!( "CodeQL installed" ) ;
6165 } else {
@@ -78,15 +82,13 @@ pub async fn codeql_download(action: &Action) -> Result<CodeQL> {
7882///
7983/// # Returns
8084/// * `Result<String>` - Path to the installed CodeQL binary or an error
81- async fn gh_codeql_download ( codeql_version : & str ) -> Result < String > {
85+ async fn gh_codeql_download ( codeql_version : & str , token : & String ) -> Result < String > {
8286 log:: info!( "Downloading CodeQL Extension for GitHub CLI..." ) ;
8387 log:: debug!( "Running command: gh extensions install github/gh-codeql" ) ;
88+
8489 let status = tokio:: process:: Command :: new ( "gh" )
8590 . args ( & [ "extensions" , "install" , "github/gh-codeql" ] )
86- . env (
87- "GH_TOKEN" ,
88- std:: env:: var ( "GITHUB_TOKEN" ) . unwrap_or_default ( ) ,
89- )
91+ . env ( "GH_TOKEN" , & token)
9092 . status ( )
9193 . await
9294 . context ( "Failed to execute `gh extensions install github/gh-codeql` command" ) ?;
@@ -107,10 +109,7 @@ async fn gh_codeql_download(codeql_version: &str) -> Result<String> {
107109 log:: debug!( "Running command: gh codeql set-version {codeql_version}" ) ;
108110 let status = tokio:: process:: Command :: new ( "gh" )
109111 . args ( & [ "codeql" , "set-version" , codeql_version] )
110- . env (
111- "GH_TOKEN" ,
112- std:: env:: var ( "GITHUB_TOKEN" ) . unwrap_or_default ( ) ,
113- )
112+ . env ( "GH_TOKEN" , & token)
114113 . status ( )
115114 . await
116115 . context ( "Failed to execute `gh codeql set-version` command" ) ?;
@@ -131,10 +130,7 @@ async fn gh_codeql_download(codeql_version: &str) -> Result<String> {
131130 log:: debug!( "Running command: gh codeql install-stub" ) ;
132131 let status = tokio:: process:: Command :: new ( "gh" )
133132 . args ( & [ "codeql" , "install-stub" ] )
134- . env (
135- "GH_TOKEN" ,
136- std:: env:: var ( "GITHUB_TOKEN" ) . unwrap_or_default ( ) ,
137- )
133+ . env ( "GH_TOKEN" , & token)
138134 . status ( )
139135 . await
140136 . context ( "Failed to execute `gh codeql install-stub` command" ) ?;
0 commit comments