Skip to content

Commit

Permalink
Merge pull request #155 from kachick/fix-154
Browse files Browse the repository at this point in the history
Ignore removed changes in license checker
  • Loading branch information
febuiles committed Jul 14, 2022
2 parents bced8aa + c003e7f commit 1dc503a
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 1 deletion.
28 changes: 28 additions & 0 deletions __tests__/licenses.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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])
})
3 changes: 3 additions & 0 deletions dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions src/licenses.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 1dc503a

Please sign in to comment.