Add logic for denied licenses.
This commit is contained in:
+8
-4
@@ -1,4 +1,3 @@
|
|||||||
import * as core from '@actions/core'
|
|
||||||
import {Change, ChangeSchema} from './schemas'
|
import {Change, ChangeSchema} from './schemas'
|
||||||
|
|
||||||
export function hasInvalidLicenses(
|
export function hasInvalidLicenses(
|
||||||
@@ -21,9 +20,14 @@ export function hasInvalidLicenses(
|
|||||||
if (license === null) {
|
if (license === null) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
if (allowLicenses.length > 0) {
|
||||||
if (!allowLicenses.includes(license)) {
|
if (!allowLicenses.includes(license)) {
|
||||||
disallowed.push(change)
|
disallowed.push(change)
|
||||||
|
}
|
||||||
|
} else if (failLicenses.length > 0) {
|
||||||
|
if (failLicenses.includes(license)) {
|
||||||
|
disallowed.push(change)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+21
-8
@@ -31,11 +31,6 @@ async function run(): Promise<void> {
|
|||||||
let minSeverity = config.fail_on_severity
|
let minSeverity = config.fail_on_severity
|
||||||
let failed = false
|
let failed = false
|
||||||
|
|
||||||
let filteredChanges = filterChangesBySeverity(
|
|
||||||
minSeverity as Severity,
|
|
||||||
changes
|
|
||||||
)
|
|
||||||
|
|
||||||
let licenseErrors = hasInvalidLicenses(
|
let licenseErrors = hasInvalidLicenses(
|
||||||
changes,
|
changes,
|
||||||
config.allow_licenses,
|
config.allow_licenses,
|
||||||
@@ -43,11 +38,20 @@ async function run(): Promise<void> {
|
|||||||
)
|
)
|
||||||
|
|
||||||
if (licenseErrors.length > 0) {
|
if (licenseErrors.length > 0) {
|
||||||
printLicensesError(licenseErrors, config.allow_licenses!)
|
printLicensesError(
|
||||||
|
licenseErrors,
|
||||||
|
config.allow_licenses,
|
||||||
|
config.deny_licenses
|
||||||
|
)
|
||||||
core.setFailed('Dependency review detected incompatible licenses.')
|
core.setFailed('Dependency review detected incompatible licenses.')
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let filteredChanges = filterChangesBySeverity(
|
||||||
|
minSeverity as Severity,
|
||||||
|
changes
|
||||||
|
)
|
||||||
|
|
||||||
for (const change of filteredChanges) {
|
for (const change of filteredChanges) {
|
||||||
if (
|
if (
|
||||||
change.change_type === 'added' &&
|
change.change_type === 'added' &&
|
||||||
@@ -114,10 +118,19 @@ function renderSeverity(
|
|||||||
|
|
||||||
function printLicensesError(
|
function printLicensesError(
|
||||||
changes: Array<Change>,
|
changes: Array<Change>,
|
||||||
allowLicenses: Array<string>
|
allowLicenses: Array<string> | undefined,
|
||||||
|
denyLicenses: Array<string> | undefined
|
||||||
): void {
|
): void {
|
||||||
core.info('Dependency review detected incompatible licenses.')
|
core.info('Dependency review detected incompatible licenses.')
|
||||||
core.info('\nAllowed licenses: ' + allowLicenses.join(', ') + '\n')
|
|
||||||
|
if (allowLicenses !== undefined) {
|
||||||
|
core.info('\nAllowed licenses: ' + allowLicenses.join(', ') + '\n')
|
||||||
|
}
|
||||||
|
|
||||||
|
if (denyLicenses !== undefined) {
|
||||||
|
core.info('\nDenied licenses: ' + denyLicenses.join(', ') + '\n')
|
||||||
|
}
|
||||||
|
|
||||||
core.info('The following dependencies have incompatible licenses:\n')
|
core.info('The following dependencies have incompatible licenses:\n')
|
||||||
for (const change of changes) {
|
for (const change of changes) {
|
||||||
core.info(
|
core.info(
|
||||||
|
|||||||
Reference in New Issue
Block a user