Skip to content

Commit

Permalink
Fixing failing tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Federico Builes committed Jun 6, 2022
1 parent bccacf9 commit 06297bf
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 8 deletions.
13 changes: 13 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -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"
}
]
}
2 changes: 1 addition & 1 deletion __tests__/licenses.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
})
7 changes: 2 additions & 5 deletions src/licenses.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import * as core from '@actions/core'
import {Change, ChangeSchema} from './schemas'

export function hasInvalidLicenses(
Expand All @@ -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<Change>): void {
return
}
18 changes: 16 additions & 2 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<void> {
try {
Expand Down Expand Up @@ -43,7 +43,7 @@ async function run(): Promise<void> {
)

if (licenseErrors.length > 0) {
printLicensesError(licenseErrors)
printLicensesError(licenseErrors, config.allow_licenses!)
throw new Error('Dependency review detected incompatible licenses.')
}

Expand Down Expand Up @@ -111,4 +111,18 @@ function renderSeverity(
return `${styles.color[color].open}(${severity} severity)${styles.color[color].close}`
}

function printLicensesError(
changes: Array<Change>,
allowLicenses: Array<string>
): 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()

0 comments on commit 06297bf

Please sign in to comment.