diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 000000000..9f9cfdc27 --- /dev/null +++ b/.vscode/launch.json @@ -0,0 +1,13 @@ +{ + "version": "0.1.0", + "configurations": [ + { + "name": "Debug Jest Tests", + "type": "node", + "request": "launch", + "runtimeArgs": ["--inspect-brk", "${workspaceRoot}/node_modules/.bin/jest", "--runInBand", "--coverage", "false"], + "console": "integratedTerminal", + "internalConsoleOptions": "neverOpen" + } + ] +} diff --git a/__tests__/licenses.test.ts b/__tests__/licenses.test.ts index b8b519339..c5d0698e5 100644 --- a/__tests__/licenses.test.ts +++ b/__tests__/licenses.test.ts @@ -49,5 +49,5 @@ let rubyChange: Change = { test('hasInvalidLicenses fails if an unallowed license is found', async () => { const changes: Changes = [npmChange, rubyChange] const result = hasInvalidLicenses(changes, ['BSD'], []) - expect(result.length).toBe(1) + expect(result[0]).toBe(npmChange) }) diff --git a/src/licenses.ts b/src/licenses.ts index ee38a4672..f40532003 100644 --- a/src/licenses.ts +++ b/src/licenses.ts @@ -1,3 +1,4 @@ +import * as core from '@actions/core' import {Change, ChangeSchema} from './schemas' export function hasInvalidLicenses( @@ -21,14 +22,10 @@ export function hasInvalidLicenses( continue } - if (allowLicenses.includes(license)) { + if (!allowLicenses.includes(license)) { disallowed.push(change) } } return disallowed } - -export function printLicensesError(changes: Array): void { - return -} diff --git a/src/main.ts b/src/main.ts index 8160b3b6d..777133441 100644 --- a/src/main.ts +++ b/src/main.ts @@ -6,7 +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' +import {hasInvalidLicenses} from './licenses' async function run(): Promise { try { @@ -43,7 +43,7 @@ async function run(): Promise { ) if (licenseErrors.length > 0) { - printLicensesError(licenseErrors) + printLicensesError(licenseErrors, config.allow_licenses!) throw new Error('Dependency review detected incompatible licenses.') } @@ -111,4 +111,18 @@ function renderSeverity( return `${styles.color[color].open}(${severity} severity)${styles.color[color].close}` } +function printLicensesError( + changes: Array, + allowLicenses: Array +): void { + core.info('Dependency review detected incompatible licenses.') + core.info('\nAllowed licenses: ' + allowLicenses.join(', ') + '\n') + core.info('The following dependencies have incompatible licenses:') + for (const change of changes) { + core.info( + `${styles.bold.open}${change.manifest} » ${change.name}@${change.version}${styles.bold.close} – ${change.license}` + ) + } +} + run()