Fix license test failures

This commit is contained in:
cnagadya
2022-10-26 09:05:22 +00:00
parent 782c57b17e
commit 3baea959cf
4 changed files with 37 additions and 17 deletions

View File

@@ -49,6 +49,15 @@ let rubyChange: Change = {
}
jest.mock('@actions/core')
jest.mock('spdx-satisfies', () => {
return {
__esModule: true,
// hack to coerce / mock spdx-satisfies to return value
// true for BSD, false for all others
// affects only deny_licenses and allow_licenses checks
default: (license: string, _: string): boolean => license === 'BSD'
}
})
const mockOctokit = {
rest: {

18
dist/index.js generated vendored
View File

@@ -175,13 +175,19 @@ function getDeniedLicenseChanges(changes, licenses) {
continue;
}
if (validityCache.get(license) === undefined) {
if (allow !== undefined) {
const found = allow.find(spdxExpression => (0, spdx_satisfies_1.default)(license, spdxExpression));
validityCache.set(license, found !== undefined);
try {
if (allow !== undefined) {
const found = allow.find(spdxExpression => (0, spdx_satisfies_1.default)(license, spdxExpression));
validityCache.set(license, found !== undefined);
}
else if (deny !== undefined) {
const found = deny.find(spdxExpression => (0, spdx_satisfies_1.default)(license, spdxExpression));
validityCache.set(license, found === undefined);
}
}
else if (deny !== undefined) {
const found = deny.find(spdxExpression => (0, spdx_satisfies_1.default)(license, spdxExpression));
validityCache.set(license, found === undefined);
catch (_) {
// eslint-disable-next-line no-console
console.log(`Invalid spdx license ${license} for ${change.name}`);
}
}
// TODO: Verify spdxSatisfies is working as expected as currently:

2
dist/index.js.map generated vendored

File diff suppressed because one or more lines are too long

View File

@@ -41,16 +41,21 @@ export async function getDeniedLicenseChanges(
}
if (validityCache.get(license) === undefined) {
if (allow !== undefined) {
const found = allow.find(spdxExpression =>
spdxSatisfies(license, spdxExpression)
)
validityCache.set(license, found !== undefined)
} else if (deny !== undefined) {
const found = deny.find(spdxExpression =>
spdxSatisfies(license, spdxExpression)
)
validityCache.set(license, found === undefined)
try {
if (allow !== undefined) {
const found = allow.find(spdxExpression =>
spdxSatisfies(license, spdxExpression)
)
validityCache.set(license, found !== undefined)
} else if (deny !== undefined) {
const found = deny.find(spdxExpression =>
spdxSatisfies(license, spdxExpression)
)
validityCache.set(license, found === undefined)
}
} catch (_) {
// eslint-disable-next-line no-console
console.log(`Invalid spdx license ${license} for ${change.name}`)
}
}