-
Notifications
You must be signed in to change notification settings - Fork 0
/
transform-audit.js
43 lines (36 loc) · 1.18 KB
/
transform-audit.js
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
let data = '';
process.stdin.setEncoding('utf8');
process.stdin.on('readable', () => {
let chunk = process.stdin.read();
if (chunk !== null) {
data += chunk;
}
});
function warningsNGSeverity(string) {
switch (string) {
case 'low': return 'LOW';
case 'moderate': return 'NORMAL';
case 'high': return 'HIGH';
case 'critical': return 'ERROR';
default: return 'NORMAL';
}
}
process.stdin.on('end', () => {
const audit = JSON.parse(data);
const actions = audit.actions;
const advisories = audit.advisories;
const issues = actions.flatMap((action) =>
action.resolves.map((resolve) => {
const advisory = advisories[resolve.id];
return {
fileName: resolve.path,
packageName: advisory.module_name,
cattegory: advisory.title,
type: action.action,
message: advisory.recommendation,
description: `${advisory.overview}\nRead more at: ${advisory.url}`,
severity: warningsNGSeverity(advisory.severity)
};
}));
console.log(JSON.stringify({ issues: issues }));
});