Skip to content

Commit

Permalink
Wrap reading and writing SARIF files
Browse files Browse the repository at this point in the history
  • Loading branch information
henrymercer committed Mar 27, 2023
1 parent fb32c3f commit 1e7a388
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 19 deletions.
8 changes: 2 additions & 6 deletions lib/codeql.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion lib/codeql.js.map

Large diffs are not rendered by default.

8 changes: 7 additions & 1 deletion lib/util.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion lib/util.js.map

Large diffs are not rendered by default.

16 changes: 6 additions & 10 deletions src/codeql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -923,11 +923,7 @@ export async function getCodeQLForCmd(
);

if (shouldExportDiagnostics) {
let sarif = JSON.parse(
fs.readFileSync(codeqlOutputFile, "utf8")
) as util.SarifFile;
sarif = util.fixInvalidNotifications(sarif, logger);
fs.writeFileSync(sarifFile, JSON.stringify(sarif));
util.fixInvalidNotificationsInFile(codeqlOutputFile, sarifFile, logger);
}

return returnState.stdout;
Expand Down Expand Up @@ -1050,11 +1046,11 @@ export async function getCodeQLForCmd(
await new toolrunner.ToolRunner(cmd, args).exec();

// Fix invalid notifications in the SARIF file output by CodeQL.
let sarif = JSON.parse(
fs.readFileSync(intermediateSarifFile, "utf8")
) as util.SarifFile;
sarif = util.fixInvalidNotifications(sarif, logger);
fs.writeFileSync(sarifFile, JSON.stringify(sarif));
util.fixInvalidNotificationsInFile(
intermediateSarifFile,
sarifFile,
logger
);
},
async diagnosticsExport(
sarifFile: string,
Expand Down
10 changes: 10 additions & 0 deletions src/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -878,3 +878,13 @@ export function fixInvalidNotifications(
}
return newSarif;
}

export function fixInvalidNotificationsInFile(
inputPath: string,
outputPath: string,
logger: Logger
): void {
let sarif = JSON.parse(fs.readFileSync(inputPath, "utf8")) as SarifFile;
sarif = fixInvalidNotifications(sarif, logger);
fs.writeFileSync(outputPath, JSON.stringify(sarif));
}

0 comments on commit 1e7a388

Please sign in to comment.