Skip to content

Commit a8f9b6a

Browse files
committed
feat: Add SARIF Tool name change
1 parent f5bff03 commit a8f9b6a

File tree

3 files changed

+22
-2
lines changed

3 files changed

+22
-2
lines changed

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,3 +30,4 @@ ghastoolkit = { version = "^0.11", features = ["toolcache"] }
3030
# GitHub API
3131
octocrab = "^0.44"
3232
openssl = { version = "0.10", features = ["vendored"] }
33+
serde_json = "1.0.140"

src/main.rs

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
use anyhow::{Context, Result};
22
use ghactions::{ActionTrait, group, groupend};
33
use ghactions_core::RepositoryReference;
4-
use ghastoolkit::codeql::database::queries::CodeQLQueries;
54
use ghastoolkit::prelude::*;
5+
use ghastoolkit::{Sarif, codeql::database::queries::CodeQLQueries};
66
use log::{debug, info};
77

88
mod action;
@@ -172,7 +172,7 @@ async fn main() -> Result<()> {
172172
match codeql
173173
.database(&database)
174174
.queries(queries)
175-
.output(sarif_path)
175+
.output(sarif_path.clone())
176176
.analyze()
177177
.await
178178
{
@@ -187,6 +187,24 @@ async fn main() -> Result<()> {
187187
}
188188
}
189189

190+
log::info!("Post-processing SARIF results");
191+
if let Ok(sarif_content) = std::fs::read_to_string(&sarif_path) {
192+
if let Ok(mut sarif) = serde_json::from_str::<Sarif>(&sarif_content) {
193+
sarif.runs.iter_mut().for_each(|run| {
194+
run.tool.driver.name = format!("CodeQL - {language}");
195+
});
196+
197+
log::debug!("Writing SARIF file to {sarif_path:?}");
198+
if let Err(e) = std::fs::write(&sarif_path, serde_json::to_string(&sarif)?)
199+
{
200+
log::error!("Failed to write SARIF file: {e}");
201+
} else {
202+
log::info!("SARIF file written successfully: {sarif_path:?}");
203+
}
204+
}
205+
206+
}
207+
190208
// Reload the database to get analysis info
191209
database.reload()?;
192210
log::info!("CodeQL Database LoC :: {}", database.lines_of_code());

0 commit comments

Comments
 (0)