@@ -149,6 +149,39 @@ pub async fn fetch_extractor(
149149 Ok ( extractor_pack)
150150}
151151
152+ /// Update the SARIF file with the extractor information (CodeQL ${language})
153+ ///
154+ /// Update only the `runs.0.tool.driver` section of the SARIF file
155+ pub fn update_sarif ( path : & PathBuf , extractor : String ) -> Result < ( ) > {
156+ let sarif_content =
157+ std:: fs:: read_to_string ( path) . context ( format ! ( "Failed to read SARIF file: {:?}" , path) ) ?;
158+ let mut sarif_json: serde_json:: Value = serde_json:: from_str ( & sarif_content)
159+ . context ( format ! ( "Failed to parse SARIF file: {:?}" , path) ) ?;
160+
161+ log:: debug!( "SARIF JSON :: {sarif_json:#?}" ) ;
162+ if let Some ( tool) = sarif_json
163+ . get_mut ( "runs" )
164+ . and_then ( |runs| runs. get_mut ( 0 ) )
165+ . and_then ( |run| run. get_mut ( "tool" ) )
166+ {
167+ if let Some ( driver) = tool. get_mut ( "driver" ) {
168+ driver[ "name" ] = serde_json:: Value :: String ( format ! ( "CodeQL - {}" , extractor) ) ;
169+ log:: info!( "Updated SARIF file with extractor: {extractor}" ) ;
170+ } else {
171+ log:: warn!( "No 'driver' field found in SARIF file" ) ;
172+ }
173+ } else {
174+ log:: warn!( "No 'runs' or 'tool' field found in SARIF file" ) ;
175+ }
176+
177+ let data = serde_json:: to_string ( & sarif_json)
178+ . context ( format ! ( "Failed to serialize SARIF JSON: {:?}" , path) ) ?;
179+ // Write the updated SARIF back to the file
180+ std:: fs:: write ( path, data)
181+ . context ( format ! ( "Failed to write SARIF file: {:?}" , path) ) ?;
182+ Ok ( ( ) )
183+ }
184+
152185/// Update the permissions for tool scripts (*.sh) and the extractor (extractor)
153186fn update_tools_permisisons ( path : & PathBuf ) -> Result < ( ) > {
154187 let tools_path = path. join ( "tools" ) ;
0 commit comments