-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e33f843
commit 7816dd7
Showing
2 changed files
with
155 additions
and
98 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,151 @@ | ||
import core from "@actions/core"; | ||
|
||
const kSuccessEmoji = "✅"; | ||
const kFailureEmoji = "❌"; | ||
const kInfoEmoji = "🟡"; | ||
|
||
function generateEmojiOutcome(reportData, hasSpecificOutcome) { | ||
if (hasSpecificOutcome) { | ||
const warnings = core.getInput("warnings"); | ||
if (warnings === "warning") { | ||
return `${kInfoEmoji} ${reportData.length}`; | ||
} else if (warnings === "off") { | ||
return "(skipped)"; | ||
} | ||
} | ||
|
||
if (reportData.length === 0) { | ||
return `${kSuccessEmoji} 0`; | ||
} | ||
|
||
return `${kFailureEmoji} ${reportData.length}`; | ||
} | ||
|
||
function generateGlobalWarningsOutcome(globalWarnings) { | ||
return `<ul> | ||
${globalWarnings.map((warning) => `<li>${warning}</li>`).join("")} | ||
</ul>`; | ||
} | ||
|
||
function generateDepsWarningsOutcome(depsWarnings) { | ||
return ` | ||
<br /> | ||
<table> | ||
<tbody> | ||
<tr> | ||
<th>Package</th> | ||
<th>Kind</th> | ||
<th>File</th> | ||
<th>Location</th> | ||
</tr> | ||
${depsWarnings | ||
.flatMap(({ warnings, package: packageName }) => | ||
warnings.map((warning) => { | ||
const location = warning.location.flatMap((location) => | ||
location.join(":") | ||
); | ||
return `<tr> | ||
<td>${packageName}</td> | ||
<td>${warning.kind}</td> | ||
<td>${warning.file}</td> | ||
<td>${location}</td> | ||
</tr>`; | ||
}) | ||
) | ||
.join("")} | ||
</tbody> | ||
</table> | ||
`; | ||
} | ||
|
||
function generateVulnsOutcome(vulns) { | ||
const vulnRanges = vuln.vulnerableRanges.join(", "); | ||
return ` | ||
<br /> | ||
<table> | ||
<tbody> | ||
<tr> | ||
<th>Package</th> | ||
<th>Severity</th> | ||
<th>Title</th> | ||
<th>Ranges</th> | ||
</tr> | ||
${vulns | ||
.map( | ||
(vuln) => | ||
`<tr> | ||
<td>${vuln.package}</td> | ||
<td>${vuln.severity}</td> | ||
<td>${vuln.title}</td> | ||
<td>${vulnRanges}</td> | ||
</tr>` | ||
) | ||
.join("")} | ||
</tbody> | ||
</table> | ||
`; | ||
} | ||
|
||
function getActionOutcome(report) { | ||
const isReportSuccessful = report.status === "success"; | ||
const emojiOutcome = isReportSuccessful ? kSuccessEmoji : kFailureEmoji; | ||
return `${emojiOutcome} [${report.status.toUpperCase()}]`; | ||
} | ||
|
||
export async function generateSummary(report) { | ||
const vulns = report.data.dependencies.vulnerabilities; | ||
const depsWarnings = report.data.dependencies.warnings; | ||
const globalWarnings = report.data.warnings; | ||
|
||
await core.summary | ||
.addHeading(getActionOutcome(report), 5) | ||
.addTable([ | ||
[ | ||
{ data: "Global warnings", header: true }, | ||
{ data: "Dependency warnings", header: true }, | ||
{ data: "Dependency vulnerabilities", header: true }, | ||
], | ||
[ | ||
generateEmojiOutcome(globalWarnings), | ||
generateEmojiOutcome(depsWarnings, true), | ||
generateEmojiOutcome(vulns), | ||
], | ||
]) | ||
.addBreak(); | ||
|
||
if (vulns.length > 0) { | ||
await core.summary | ||
.addDetails( | ||
`(${generateEmojiOutcome(vulns)}) <u>Dependencies vulnerabilities:</u>`, | ||
generateVulnsOutcome(vulns) | ||
) | ||
.addList(generateVulnsOutcome(vulns)); | ||
await core.summary.addSeparator(); | ||
} | ||
|
||
if (globalWarnings.length > 0) { | ||
await core.summary.addDetails( | ||
`(${generateEmojiOutcome(globalWarnings)}) <u>Global warnings:</u>`, | ||
generateGlobalWarningsOutcome(globalWarnings) | ||
); | ||
await core.summary.addSeparator(); | ||
} | ||
|
||
if (depsWarnings.length > 0) { | ||
await core.summary.addDetails( | ||
`(${generateEmojiOutcome( | ||
depsWarnings, | ||
true | ||
)}) <u>Dependencies warnings:</u>`, | ||
generateDepsWarningsOutcome(depsWarnings) | ||
); | ||
} | ||
|
||
await core.summary | ||
.addSeparator() | ||
.addLink( | ||
"View @nodesecure/ci documentation", | ||
"https://github.com/NodeSecure/ci" | ||
) | ||
.write(); | ||
} |