Skip to content

Commit e823681

Browse files
committed
refactor: Enhance logging for extractor fetching and CodeQL installation processes
1 parent d73b981 commit e823681

4 files changed

Lines changed: 314 additions & 49 deletions

File tree

src/action.rs

Lines changed: 30 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -137,25 +137,44 @@ impl Action {
137137
return Ok(vec![Repository::parse(&self.get_repository()?)?]);
138138
}
139139

140-
log::debug!("Using the provided extractor repository");
140+
log::debug!(
141+
"Using the provided extractor repositories: {:?}",
142+
self.extractors
143+
);
141144

142-
Ok(self
145+
let repos: Vec<Repository> = self
143146
.extractors
144147
.iter()
145-
.filter_map(|ext| {
146-
Repository::parse(ext)
147-
.context(format!("Failed to parse extractor repository `{ext}`"))
148-
.ok()
148+
.filter_map(|ext| match Repository::parse(ext) {
149+
Ok(repo) => {
150+
log::debug!(
151+
"Successfully parsed repository: {} / {}",
152+
repo.owner,
153+
repo.name
154+
);
155+
Some(repo)
156+
}
157+
Err(e) => {
158+
log::warn!("Failed to parse extractor repository `{}`: {}", ext, e);
159+
None
160+
}
149161
})
150-
.collect::<Vec<Repository>>())
162+
.collect();
163+
164+
log::debug!("Parsed {} repositories", repos.len());
165+
Ok(repos)
151166
}
152167

153168
/// Returns the list of languages to use for CodeQL analysis.
154169
pub fn languages(&self) -> Vec<CodeQLLanguage> {
155-
self.languages
170+
log::debug!("Getting languages for analysis: {:?}", self.languages);
171+
let languages = self
172+
.languages
156173
.iter()
157174
.map(|lang| CodeQLLanguage::from(lang.as_str()))
158-
.collect()
175+
.collect();
176+
log::debug!("Converted to CodeQL languages: {:?}", languages);
177+
languages
159178
}
160179

161180
/// Returns the directory to use for CodeQL operations.
@@ -269,11 +288,13 @@ impl Action {
269288

270289
/// Returns whether attestation is enabled.
271290
pub fn attestation(&self) -> bool {
291+
log::debug!("Attestation enabled: {}", self.attestation);
272292
self.attestation
273293
}
274294

275295
/// Returns whether empty databases are allowed.
276296
pub fn allow_empty_database(&self) -> bool {
297+
log::debug!("Allow empty database: {}", self.allow_empty_database);
277298
self.allow_empty_database
278299
}
279300
}

src/codeql.rs

Lines changed: 45 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
//! CodeQL installation and management utilities
22
//!
33
//! This module provides helper functions for downloading and installing CodeQL,
4-
//! particularly through alternative methods like GitHub CLI when the standard
4+
//! particularly through alternative methods like GitHub CLI when the standard
55
//! installation process fails.
66
77
use anyhow::{Context, Result};
88
use ghastoolkit::CodeQL;
99

1010
/// Download and install the CodeQL CLI using the GitHub CLI
1111
///
12-
/// This function serves as a fallback installation method when the standard CodeQL
12+
/// This function serves as a fallback installation method when the standard CodeQL
1313
/// installation process fails. It uses the GitHub CLI to:
1414
/// 1. Install the gh-codeql extension
1515
/// 2. Set the specified CodeQL version
@@ -22,26 +22,65 @@ use ghastoolkit::CodeQL;
2222
/// * `Result<String>` - Path to the installed CodeQL binary or an error
2323
pub async fn gh_codeql_download(codeql_version: &str) -> Result<String> {
2424
log::info!("Downloading CodeQL Extension for GitHub CLI...");
25-
tokio::process::Command::new("gh")
25+
log::debug!("Running command: gh extensions install github/gh-codeql");
26+
let status = tokio::process::Command::new("gh")
2627
.args(&["extensions", "install", "github/gh-codeql"])
2728
.status()
2829
.await
2930
.context("Failed to execute `gh extensions install github/gh-codeql` command")?;
3031

32+
if !status.success() {
33+
log::error!(
34+
"Failed to install GitHub CLI CodeQL extension. Exit code: {:?}",
35+
status.code()
36+
);
37+
return Err(anyhow::anyhow!(
38+
"GitHub CLI CodeQL extension installation failed with exit code: {:?}",
39+
status.code()
40+
));
41+
}
42+
log::debug!("GitHub CLI CodeQL extension installed successfully");
43+
3144
log::info!("Setting CodeQL version to {codeql_version}...");
32-
tokio::process::Command::new("gh")
45+
log::debug!("Running command: gh codeql set-version {codeql_version}");
46+
let status = tokio::process::Command::new("gh")
3347
.args(&["codeql", "set-version", codeql_version])
3448
.status()
3549
.await
3650
.context("Failed to execute `gh codeql set-version` command")?;
3751

38-
log::info!("Install CodeQL stub...");
39-
tokio::process::Command::new("gh")
52+
if !status.success() {
53+
log::error!(
54+
"Failed to set CodeQL version. Exit code: {:?}",
55+
status.code()
56+
);
57+
return Err(anyhow::anyhow!(
58+
"Setting CodeQL version failed with exit code: {:?}",
59+
status.code()
60+
));
61+
}
62+
log::debug!("CodeQL version set to {codeql_version} successfully");
63+
64+
log::info!("Installing CodeQL stub...");
65+
log::debug!("Running command: gh codeql install-stub");
66+
let status = tokio::process::Command::new("gh")
4067
.args(&["codeql", "install-stub"])
4168
.status()
4269
.await
4370
.context("Failed to execute `gh codeql install-stub` command")?;
4471

72+
if !status.success() {
73+
log::error!(
74+
"Failed to install CodeQL stub. Exit code: {:?}",
75+
status.code()
76+
);
77+
return Err(anyhow::anyhow!(
78+
"CodeQL stub installation failed with exit code: {:?}",
79+
status.code()
80+
));
81+
}
82+
log::debug!("CodeQL stub installed successfully");
83+
4584
let codeql = CodeQL::new().await;
4685
if codeql.is_installed().await {
4786
log::info!("CodeQL CLI installed successfully via GitHub CLI");

0 commit comments

Comments
 (0)