Skip to content

Commit

Permalink
Merge pull request #280 from actions/format-bugs
Browse files Browse the repository at this point in the history
Fix display issues with versions and GHSAs
  • Loading branch information
Federico Builes authored Oct 11, 2022
2 parents 6f58092 + 88b817e commit f076f22
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 18 deletions.
18 changes: 12 additions & 6 deletions __tests__/filter.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import {Change, Changes} from '../src/schemas'
import {
filterChangesBySeverity,
filterChangesByScopes,
filterOutAllowedAdvisories
filterAllowedAdvisories
} from '../src/filter'

let npmChange: Change = {
Expand Down Expand Up @@ -90,28 +90,34 @@ test('it properly filters changes by scope', async () => {
expect(result).toEqual([npmChange, rubyChange])
})

test('it properly handles undefined advisory IDs', async () => {
const changes = [npmChange, rubyChange, noVulnNpmChange]
let result = filterAllowedAdvisories(undefined, changes)
expect(result).toEqual([npmChange, rubyChange, noVulnNpmChange])
})

test('it properly filters changes with allowed vulnerabilities', async () => {
const changes = [npmChange, rubyChange, noVulnNpmChange]

let result = filterOutAllowedAdvisories(['notrealGHSAID'], changes)
let result = filterAllowedAdvisories(['notrealGHSAID'], changes)
expect(result).toEqual([npmChange, rubyChange, noVulnNpmChange])

result = filterOutAllowedAdvisories(['first-random_string'], changes)
result = filterAllowedAdvisories(['first-random_string'], changes)
expect(result).toEqual([rubyChange, noVulnNpmChange])

result = filterOutAllowedAdvisories(
result = filterAllowedAdvisories(
['second-random_string', 'third-random_string'],
changes
)
expect(result).toEqual([npmChange, noVulnNpmChange])

result = filterOutAllowedAdvisories(
result = filterAllowedAdvisories(
['first-random_string', 'second-random_string', 'third-random_string'],
changes
)
expect(result).toEqual([noVulnNpmChange])

// if we have a change with multiple vulnerabilities but only one is allowed, we still should not filter out that change
result = filterOutAllowedAdvisories(['second-random_string'], changes)
result = filterAllowedAdvisories(['second-random_string'], changes)
expect(result).toEqual([npmChange, rubyChange, noVulnNpmChange])
})
20 changes: 14 additions & 6 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.

12 changes: 10 additions & 2 deletions src/filter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,20 @@ export function filterChangesByScopes(
return filteredChanges
}

export function filterOutAllowedAdvisories(
/**
* Filter out changes that are allowed by the allow_ghsas config
* option. We want to remove these changes before we do any
* processing.
* @param ghsas - list of GHSA IDs to allow
* @param changes - list of changes to filter
* @returns a list of changes with the allowed GHSAs removed
*/
export function filterAllowedAdvisories(
ghsas: string[] | undefined,
changes: Changes
): Changes {
if (ghsas === undefined) {
return []
return changes
}

const filteredChanges = changes.filter(change => {
Expand Down
6 changes: 3 additions & 3 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {readConfig} from '../src/config'
import {
filterChangesBySeverity,
filterChangesByScopes,
filterOutAllowedAdvisories
filterAllowedAdvisories
} from '../src/filter'
import {getDeniedLicenseChanges} from './licenses'
import * as summary from './summary'
Expand All @@ -30,7 +30,7 @@ async function run(): Promise<void> {

const minSeverity = config.fail_on_severity as Severity
const scopedChanges = filterChangesByScopes(config.fail_on_scopes, changes)
const filteredChanges = filterOutAllowedAdvisories(
const filteredChanges = filterAllowedAdvisories(
config.allow_ghsas,
scopedChanges
)
Expand Down Expand Up @@ -192,7 +192,7 @@ function renderScannedDependency(change: Change): string {
} as const
)[changeType]

return `${styles.color[color].open}${icon} ${change.manifest}@${change.version}${styles.color[color].close}`
return `${styles.color[color].open}${icon} ${change.name}@${change.version}${styles.color[color].close}`
}

function printScannedDependencies(changes: Changes): void {
Expand Down

0 comments on commit f076f22

Please sign in to comment.