-
Notifications
You must be signed in to change notification settings - Fork 0
/
reportGeneration.js
92 lines (83 loc) · 2.79 KB
/
reportGeneration.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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
const fs = require('fs');
function generateReport(violations, reportFilePath) {
fs.writeFileSync(reportFilePath, JSON.stringify(violations, null, 4));
}
function generateHtmlReport(devmanViolations, ctcViolations, dockerViolations, packageJson, datetimeSuffix, htmlReportFilePath) {
const devmanHtml = generateViolationTable(devmanViolations, 'DevMan Violations');
const ctcHtml = generateViolationTable(ctcViolations, 'CTC Violations');
const dockerHtml = generateViolationTable(dockerViolations, 'Dockerfile Violations');
const summary = generateSummary(devmanViolations, ctcViolations, dockerViolations);
const htmlContent = `
<!DOCTYPE html>
<html>
<head>
<title>Scan Report</title>
<style>
table {
border-collapse: collapse;
width: 100%;
}
th, td {
border: 1px solid #dddddd;
text-align: left;
padding: 8px;
}
th {
background-color: #f2f2f2;
}
.search-container {
margin-top: 10px;
margin-bottom: 10px;
}
</style>
</head>
<body>
<h1>Scan Report</h1>
<p>Application Name: ${packageJson.name}</p>
<p>Application Version: ${packageJson.version}</p>
<p>Scan Date: ${datetimeSuffix}</p>
${summary}
${devmanHtml}
${ctcHtml}
${dockerHtml}
</body>
</html>
`;
fs.writeFileSync(htmlReportFilePath, htmlContent);
}
function generateViolationTable(violations, title) {
if (violations.length === 0) {
return '';
}
const html = `
<h2>${title}:</h2>
<table>
<tr>
<th>File</th>
<th>Line Number</th>
<th>Violation</th>
</tr>
${violations.map(violation => `
<tr>
<td>${violation.file || ''}</td>
<td>${violation.lineNumber !== -1 ? violation.lineNumber : '-'}</td>
<td>${violation.ruleMatched || violation.dependency || violation.violation}</td>
</tr>
`).join('')}
</table>
`;
return html;
}
function generateSummary(devmanViolations, ctcViolations, dockerViolations) {
const summary = `
<h2>Summary:</h2>
<p>Total DevMan Violations: ${devmanViolations.length}</p>
<p>Total CTC Violations: ${ctcViolations.length}</p>
<p>Total Dockerfile Violations: ${dockerViolations.length}</p>
`;
return summary;
}
module.exports = {
generateHtmlReport,
generateReport
};