Skip to content

Commit

Permalink
Tiny logic refactor.
Browse files Browse the repository at this point in the history
  • Loading branch information
febuiles committed Nov 24, 2023
1 parent 7bbfa03 commit 50dafeb
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 7 deletions.
17 changes: 16 additions & 1 deletion src/filter.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
import {Changes, Severity, SEVERITIES, Scope} from './schemas'

/**
* Filters changes by a severity level. Only vulnerable
* dependencies will be returned.
*
* @param severity - The severity level to filter by.
* @param changes - The array of changes to filter.
* @returns The filtered array of changes that match the specified severity level and have vulnerabilities.
*/
export function filterChangesBySeverity(
severity: Severity,
changes: Changes
Expand Down Expand Up @@ -31,7 +39,14 @@ export function filterChangesBySeverity(
filteredChanges = filteredChanges.filter(
change => change.vulnerabilities.length > 0
)
return filteredChanges

// only report vulnerability additions
return filteredChanges.filter(
change =>
change.change_type === 'added' &&
change.vulnerabilities !== undefined &&
change.vulnerabilities.length > 0
)
}

export function filterChangesByScopes(
Expand Down
8 changes: 2 additions & 6 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,21 +80,17 @@ async function run(): Promise<void> {
return
}

const minSeverity = config.fail_on_severity
const scopedChanges = filterChangesByScopes(config.fail_on_scopes, changes)

const filteredChanges = filterAllowedAdvisories(
config.allow_ghsas,
scopedChanges
)

const minSeverity = config.fail_on_severity
const vulnerableChanges = filterChangesBySeverity(
minSeverity,
filteredChanges
).filter(
change =>
change.change_type === 'added' &&
change.vulnerabilities !== undefined &&
change.vulnerabilities.length > 0
)

const invalidLicenseChanges = await getInvalidLicenseChanges(
Expand Down

0 comments on commit 50dafeb

Please sign in to comment.