Handle unknown licenses.

This commit is contained in:
Federico Builes
2022-06-14 13:54:27 +02:00
parent 0b87f02bee
commit 42e2bc1ed2
5 changed files with 49 additions and 27 deletions
+22 -10
View File
@@ -36,14 +36,6 @@ async function run(): Promise<void> {
deny: config.deny_licenses
}
let licenseErrors = getDeniedLicenseChanges(changes, licenses)
if (licenseErrors.length > 0) {
printLicensesError(licenseErrors, licenses)
core.setFailed('Dependency review detected incompatible licenses.')
return
}
let filteredChanges = filterChangesBySeverity(
minSeverity as Severity,
changes
@@ -60,8 +52,19 @@ async function run(): Promise<void> {
}
}
let [licenseErrors, unknownLicenses] = getDeniedLicenseChanges(
changes,
licenses
)
if (licenseErrors.length > 0) {
printLicensesError(licenseErrors, licenses)
printNullLicenses(unknownLicenses)
core.setFailed('Dependency review detected incompatible licenses.')
}
if (failed) {
throw new Error('Dependency review detected vulnerable packages.')
core.setFailed('Dependency review detected vulnerable packages.')
} else {
core.info(
`Dependency review did not detect any vulnerable packages with severity level "${minSeverity}" or higher.`
@@ -126,7 +129,7 @@ function printLicensesError(
let {allow = [], deny = []} = licenses
core.info('The following dependencies have incompatible licenses:\n')
core.info('\nThe following dependencies have incompatible licenses:\n')
for (const change of changes) {
core.info(
`${styles.bold.open}${change.manifest} » ${change.name}@${change.version}${styles.bold.close} License: ${styles.color.red.open}${change.license}${styles.color.red.close}`
@@ -134,4 +137,13 @@ function printLicensesError(
}
}
function printNullLicenses(changes: Array<Change>): void {
core.info('\nWe could not detect a license for the following dependencies:\n')
for (const change of changes) {
core.info(
`${styles.bold.open}${change.manifest} » ${change.name}@${change.version}${styles.bold.close}`
)
}
}
run()