-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathrunner.js
More file actions
76 lines (63 loc) · 2.31 KB
/
runner.js
File metadata and controls
76 lines (63 loc) · 2.31 KB
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
// const core = require('@actions/core');
const fs = require('fs').promises;
const _fs = require('fs');
const sarifLoader = require('./sarifLoader');
const resultProcessor = require('./sarifProcessors/resultProcessor');
const ruleProcessor = require('./sarifProcessors/ruleProcessor');
const logger = require('./logger');
const OUTPUT_DIR = 'processed-sarifs';
async function writeOutputFile(outFilename, data) {
try {
await fs.writeFile(outFilename, data, 'utf8');
}
catch (e) {
console.error(`Error writing file: ${outFilename}`, e);
}
}
async function run(inFile, outFile, languageKey, onFailure) {
try {
const pathType = await sarifLoader.getPathType(inFile);
let fileCount = 1;
logger.debug(`Input path type: ${pathType}`);
if (pathType !== 'file') {
const exists = _fs.existsSync(OUTPUT_DIR);
if (!exists) {
await fs.mkdir(OUTPUT_DIR);
}
}
console.log(inFile);
// load SARIF file from input location
const sarifs = await sarifLoader.load(inFile);
for (const sarif of sarifs) {
// logger.debug(JSON.stringify(sarif, null, 4));
// process each run
if (sarif && sarif.runs) {
for (const run of sarif.runs) {
// process run for results
const triggeredRules = await resultProcessor.process(run, languageKey);
// process run for rules
await ruleProcessor.processRun(run, languageKey, triggeredRules);
}
}
// write SARIF file to output location
const outputData = JSON.stringify(sarif);
// logger.debug(JSON.stringify(sarif, null, 4));
if (pathType === 'file') {
logger.debug(`Writing file: ${outFile}`);
await writeOutputFile(outFile, outputData);
}
else {
const outPath = `./${OUTPUT_DIR}/${fileCount}.sarif`;
logger.debug(`Writing file: ${outPath}`);
await writeOutputFile(outPath, outputData);
}
fileCount++;
}
} catch (error) {
onFailure(error.message);
throw error;
}
}
module.exports = {
run
}