Skeleton for license validation.

This commit is contained in:
Federico Builes
2022-06-06 20:32:46 +02:00
parent 8c646c1c91
commit bccacf9708
6 changed files with 115 additions and 0 deletions
+34
View File
@@ -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
View File
@@ -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' &&