Fix license test failures

This commit is contained in:
cnagadya
2022-10-26 09:58:00 +00:00
parent 782c57b17e
commit 3baea959cf
4 changed files with 37 additions and 17 deletions
+9
View File
@@ -49,6 +49,15 @@ let rubyChange: Change = {
} }
jest.mock('@actions/core') 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 = { const mockOctokit = {
rest: { rest: {
Generated Vendored
+12 -6
View File
@@ -175,13 +175,19 @@ function getDeniedLicenseChanges(changes, licenses) {
continue; continue;
} }
if (validityCache.get(license) === undefined) { if (validityCache.get(license) === undefined) {
if (allow !== undefined) { try {
const found = allow.find(spdxExpression => (0, spdx_satisfies_1.default)(license, spdxExpression)); if (allow !== undefined) {
validityCache.set(license, found !== 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) { catch (_) {
const found = deny.find(spdxExpression => (0, spdx_satisfies_1.default)(license, spdxExpression)); // eslint-disable-next-line no-console
validityCache.set(license, found === undefined); console.log(`Invalid spdx license ${license} for ${change.name}`);
} }
} }
// TODO: Verify spdxSatisfies is working as expected as currently: // TODO: Verify spdxSatisfies is working as expected as currently:
Generated Vendored
+1 -1
View File
File diff suppressed because one or more lines are too long
+15 -10
View File
@@ -41,16 +41,21 @@ export async function getDeniedLicenseChanges(
} }
if (validityCache.get(license) === undefined) { if (validityCache.get(license) === undefined) {
if (allow !== undefined) { try {
const found = allow.find(spdxExpression => if (allow !== undefined) {
spdxSatisfies(license, spdxExpression) const found = allow.find(spdxExpression =>
) spdxSatisfies(license, spdxExpression)
validityCache.set(license, found !== undefined) )
} else if (deny !== undefined) { validityCache.set(license, found !== undefined)
const found = deny.find(spdxExpression => } else if (deny !== undefined) {
spdxSatisfies(license, spdxExpression) const found = deny.find(spdxExpression =>
) spdxSatisfies(license, spdxExpression)
validityCache.set(license, found === undefined) )
validityCache.set(license, found === undefined)
}
} catch (_) {
// eslint-disable-next-line no-console
console.log(`Invalid spdx license ${license} for ${change.name}`)
} }
} }