@@ -21,6 +21,7 @@ import * as gitUtils from "./git-utils";
2121import { initCodeQL } from "./init" ;
2222import { Logger } from "./logging" ;
2323import { getRepositoryNwo , RepositoryNwo } from "./repository" ;
24+ import type { SarifFile , SarifRun } from "./sarif" ;
2425import { BasePayload , UploadPayload } from "./upload-lib/types" ;
2526import * as util from "./util" ;
2627import {
@@ -30,8 +31,6 @@ import {
3031 GitHubVariant ,
3132 GitHubVersion ,
3233 satisfiesGHESVersion ,
33- SarifFile ,
34- SarifRun ,
3534} from "./util" ;
3635
3736const GENERIC_403_MSG =
@@ -50,9 +49,7 @@ function combineSarifFiles(sarifFiles: string[], logger: Logger): SarifFile {
5049
5150 for ( const sarifFile of sarifFiles ) {
5251 logger . debug ( `Loading SARIF file: ${ sarifFile } ` ) ;
53- const sarifObject = JSON . parse (
54- fs . readFileSync ( sarifFile , "utf8" ) ,
55- ) as SarifFile ;
52+ const sarifObject = util . readSarifFile ( sarifFile ) ;
5653 // Check SARIF version
5754 if ( combinedSarif . version === null ) {
5855 combinedSarif . version = sarifObject . version ;
@@ -195,9 +192,7 @@ async function combineSarifFilesUsingCLI(
195192) : Promise < SarifFile > {
196193 logger . info ( "Combining SARIF files using the CodeQL CLI" ) ;
197194
198- const sarifObjects = sarifFiles . map ( ( sarifFile ) : SarifFile => {
199- return JSON . parse ( fs . readFileSync ( sarifFile , "utf8" ) ) as SarifFile ;
200- } ) ;
195+ const sarifObjects = sarifFiles . map ( util . readSarifFile ) ;
201196
202197 const deprecationWarningMessage =
203198 gitHubVersion . type === GitHubVariant . GHES
@@ -279,7 +274,7 @@ async function combineSarifFilesUsingCLI(
279274 mergeRunsFromEqualCategory : true ,
280275 } ) ;
281276
282- return JSON . parse ( fs . readFileSync ( outputFile , "utf8" ) ) as SarifFile ;
277+ return util . readSarifFile ( outputFile ) ;
283278}
284279
285280// Populates the run.automationDetails.id field using the analysis_key and environment
@@ -531,7 +526,7 @@ function countResultsInSarif(sarif: string): number {
531526
532527export function readSarifFile ( sarifFilePath : string ) : SarifFile {
533528 try {
534- return JSON . parse ( fs . readFileSync ( sarifFilePath , "utf8" ) ) as SarifFile ;
529+ return util . readSarifFile ( sarifFilePath ) ;
535530 } catch ( e ) {
536531 throw new InvalidSarifUploadError (
537532 `Invalid SARIF. JSON syntax error: ${ getErrorMessage ( e ) } ` ,
0 commit comments