-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
61 lines (47 loc) · 1.81 KB
/
index.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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
const core = require('@actions/core');
const fs = require('fs')
try {
// Load the SARIF report
const rawData = fs.readFileSync(core.getInput('sarif-file'), 'utf8');
const data = JSON.parse(rawData);
const engine = data.runs[0].tool.driver.name;
const sonarIssues = [];
// Loop through all of the items
for (const result of data.runs[0].results) {
const location = result.locations[0].physicalLocation;
let startColumn = location.region.startColumn -1;
let endColumn = location.region.endColumn -1; // https://docs.oasis-open.org/sarif/sarif/v2.0/csprd02/sarif-v2.0-csprd02.html#_Toc10127881
if (startColumn >= endColumn) {
startColumn = endColumn-1; // Start must be less than end
}
if (startColumn < 0) {
startColumn = 0;
}
if (endColumn < 0) {
endColumn = 0;
}
// Transform into Sonar's format
const issue = {
engineId: engine,
ruleId: result.ruleId,
severity: 'MINOR', // BLOCKER, CRITICAL, MAJOR, MINOR, INFO
type: 'CODE_SMELL', // BUG, VULNERABILITY, CODE_SMELL
primaryLocation: {
message: result.message.text,
filePath: location.artifactLocation.uri,
textRange: {
startLine: location.region.startLine,
endLine: location.region.endLine,
startColumn: startColumn,
endColumn: endColumn
}
}
}
sonarIssues.push(issue);
}
// Save the output file
const content = JSON.stringify({ issues: sonarIssues});
fs.writeFileSync(core.getInput('sonar-file'), content);
} catch (error) {
core.setFailed(error.message);
}