forked from github/codeql
-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathsplit-sarif.js
More file actions
30 lines (25 loc) · 795 Bytes
/
Copy pathsplit-sarif.js
File metadata and controls
30 lines (25 loc) · 795 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
var fs = require("fs");
// the .sarif file to split, and then the directory to put the split files in.
async function main(inputs) {
const sarifFile = JSON.parse(fs.readFileSync(inputs[0]));
const outFolder = inputs[1];
const out = {};
for (const result of sarifFile.runs[0].results) {
const lang = getLanguage(result);
if (!out[lang]) {
out[lang] = [];
}
out[lang].push(result);
}
for (const lang in out) {
const outSarif = JSON.parse(JSON.stringify(sarifFile));
outSarif.runs[0].results = out[lang];
fs.writeFileSync(`${outFolder}/${lang}.sarif`, JSON.stringify(outSarif, null, 2));
}
}
function getLanguage(result) {
return result.locations[0].physicalLocation.artifactLocation.uri.split(
"/"
)[0];
}
main(process.argv.splice(2));