Merge pull request #155 from kachick/fix-154

Ignore removed changes in license checker
This commit is contained in:
Federico Builes
2022-07-14 09:10:17 +02:00
committed by GitHub
4 changed files with 36 additions and 1 deletions
+28
View File
@@ -68,3 +68,31 @@ test('it fails all license checks when allow is provided an empty array', async
})
expect(invalidChanges.length).toBe(2)
})
test('it does not fail if a license outside the allow list is found in removed changes', async () => {
const changes: Changes = [
{...npmChange, change_type: 'removed'},
{...rubyChange, change_type: 'removed'}
]
const [invalidChanges, _] = getDeniedLicenseChanges(changes, {allow: ['BSD']})
expect(invalidChanges).toStrictEqual([])
})
test('it does not fail if a license inside the deny list is found in removed changes', async () => {
const changes: Changes = [
{...npmChange, change_type: 'removed'},
{...rubyChange, change_type: 'removed'}
]
const [invalidChanges, _] = getDeniedLicenseChanges(changes, {deny: ['BSD']})
expect(invalidChanges).toStrictEqual([])
})
test('it fails if a license outside the allow list is found in both of added and removed changes', async () => {
const changes: Changes = [
{...npmChange, change_type: 'removed'},
npmChange,
{...rubyChange, change_type: 'removed'}
]
const [invalidChanges, _] = getDeniedLicenseChanges(changes, {allow: ['BSD']})
expect(invalidChanges).toStrictEqual([npmChange])
})
Generated Vendored
+3
View File
@@ -85,6 +85,9 @@ function getDeniedLicenseChanges(changes, licenses) {
const disallowed = [];
const unknown = [];
for (const change of changes) {
if (change.change_type === 'removed') {
continue;
}
const license = change.license;
if (license === null) {
unknown.push(change);
Generated Vendored
+1 -1
View File
File diff suppressed because one or more lines are too long
+4
View File
@@ -25,6 +25,10 @@ export function getDeniedLicenseChanges(
const unknown: Change[] = []
for (const change of changes) {
if (change.change_type === 'removed') {
continue
}
const license = change.license
if (license === null) {
unknown.push(change)