36 lines
889 B
TypeScript
36 lines
889 B
TypeScript
import {Changes, Severity, SEVERITIES} from './schemas'
|
|
|
|
export function filterChangesBySeverity(
|
|
severity: Severity,
|
|
changes: Changes
|
|
): Changes {
|
|
const severityIdx = SEVERITIES.indexOf(severity)
|
|
let filteredChanges = []
|
|
for (const change of changes) {
|
|
if (
|
|
change === undefined ||
|
|
change.vulnerabilities === undefined ||
|
|
change.vulnerabilities.length === 0
|
|
) {
|
|
continue
|
|
}
|
|
|
|
const fChange = {
|
|
...change,
|
|
vulnerabilities: change.vulnerabilities.filter(vuln => {
|
|
const vulnIdx = SEVERITIES.indexOf(vuln.severity)
|
|
if (vulnIdx <= severityIdx) {
|
|
return true
|
|
}
|
|
})
|
|
}
|
|
filteredChanges.push(fChange)
|
|
}
|
|
|
|
// don't want to deal with changes with no vulnerabilities
|
|
filteredChanges = filteredChanges.filter(
|
|
change => change.vulnerabilities.length > 0
|
|
)
|
|
return filteredChanges
|
|
}
|