From 062b7496634855bde37a5c09ae0f94afedf1f0c2 Mon Sep 17 00:00:00 2001 From: Sarah Aladetan Date: Thu, 22 Sep 2022 22:36:34 +0000 Subject: [PATCH] revise ghsa filter --- src/filter.ts | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/src/filter.ts b/src/filter.ts index 35c574b..8964621 100644 --- a/src/filter.ts +++ b/src/filter.ts @@ -51,27 +51,26 @@ export function filterOutAllowedAdvisories( ghsas: string[], changes: Changes ): Changes { - let filteredChanges = [] - for (const change of changes) { - if ( + const filteredChanges = changes.filter(change => { + const noAdvisories = change.vulnerabilities === undefined || change.vulnerabilities.length === 0 - ) { - filteredChanges.push(change) - continue + + if (noAdvisories) { + return true } - let allVulnsAllowed = true + let allAllowedAdvisories = true + // if there's at least one advisory that is not allowlisted, we will keep the change for (const vulnerability of change.vulnerabilities) { if (!ghsas.includes(vulnerability.advisory_ghsa_id)) { - allVulnsAllowed = false + allAllowedAdvisories = false + } + if (!allAllowedAdvisories) { + return true } } - - if (allVulnsAllowed === false) { - filteredChanges.push(change) - } - } + }) return filteredChanges }