Skeleton for license validation.
This commit is contained in:
@@ -0,0 +1,34 @@
|
||||
import {Change, ChangeSchema} from './schemas'
|
||||
|
||||
export function hasInvalidLicenses(
|
||||
changes: Array<Change>,
|
||||
allowLicenses: Array<string> | undefined,
|
||||
failLicenses: Array<string> | undefined
|
||||
): Array<Change> {
|
||||
let disallowed: Change[] = []
|
||||
|
||||
if (allowLicenses === undefined) {
|
||||
allowLicenses = []
|
||||
}
|
||||
if (failLicenses === undefined) {
|
||||
failLicenses = []
|
||||
}
|
||||
|
||||
for (const change of changes) {
|
||||
let license = change.license
|
||||
// TODO: be loud about unknown licenses
|
||||
if (license === null) {
|
||||
continue
|
||||
}
|
||||
|
||||
if (allowLicenses.includes(license)) {
|
||||
disallowed.push(change)
|
||||
}
|
||||
}
|
||||
|
||||
return disallowed
|
||||
}
|
||||
|
||||
export function printLicensesError(changes: Array<Change>): void {
|
||||
return
|
||||
}
|
||||
+12
@@ -6,6 +6,7 @@ import {RequestError} from '@octokit/request-error'
|
||||
import {Change, PullRequestSchema, Severity} from './schemas'
|
||||
import {readConfigFile} from '../src/config'
|
||||
import {filterChangesBySeverity} from '../src/filter'
|
||||
import {hasInvalidLicenses, printLicensesError} from './licenses'
|
||||
|
||||
async function run(): Promise<void> {
|
||||
try {
|
||||
@@ -35,6 +36,17 @@ async function run(): Promise<void> {
|
||||
changes
|
||||
)
|
||||
|
||||
let licenseErrors = hasInvalidLicenses(
|
||||
changes,
|
||||
config.allow_licenses,
|
||||
config.deny_licenses
|
||||
)
|
||||
|
||||
if (licenseErrors.length > 0) {
|
||||
printLicensesError(licenseErrors)
|
||||
throw new Error('Dependency review detected incompatible licenses.')
|
||||
}
|
||||
|
||||
for (const change of filteredChanges) {
|
||||
if (
|
||||
change.change_type === 'added' &&
|
||||
|
||||
Reference in New Issue
Block a user