From 827f1e875058532b7ce1587d782bf04c0df07523 Mon Sep 17 00:00:00 2001 From: Ronald Arias Date: Mon, 15 Jul 2024 17:05:44 -0500 Subject: [PATCH] validate repository object outside converter --- src/steps/secretScanningAlerts.ts | 16 ++++++---------- src/sync/converters.ts | 3 --- 2 files changed, 6 insertions(+), 13 deletions(-) diff --git a/src/steps/secretScanningAlerts.ts b/src/steps/secretScanningAlerts.ts index 9258639..6c9a842 100644 --- a/src/steps/secretScanningAlerts.ts +++ b/src/steps/secretScanningAlerts.ts @@ -28,19 +28,15 @@ export async function fetchSecretScanningAlerts({ const restClient = getOrCreateRestClient(config, logger); await restClient.iterateSecretScanningAlerts(async (alert) => { - const secretScanningAlertEntity = createSecretScanningAlertEntity( - alert, - ) as SecretScanningFindingEntity; - if (!secretScanningAlertEntity) { + if (!alert.repository?.node_id) { return; } - await jobState.addEntity(secretScanningAlertEntity); + const secretScanningAlertEntity = await jobState.addEntity( + createSecretScanningAlertEntity(alert) as SecretScanningFindingEntity, + ); - const repoEntityKey = - alert.repository?.node_id && - getRepositoryEntityKey(alert.repository.node_id); - - if (repoEntityKey && jobState.hasKey(repoEntityKey)) { + const repoEntityKey = getRepositoryEntityKey(alert.repository.node_id); + if (jobState.hasKey(repoEntityKey)) { await jobState.addRelationship( createDirectRelationship({ _class: RelationshipClass.HAS, diff --git a/src/sync/converters.ts b/src/sync/converters.ts index 558031f..89f9462 100755 --- a/src/sync/converters.ts +++ b/src/sync/converters.ts @@ -204,9 +204,6 @@ export function getSecretScanningAlertKey( export function createSecretScanningAlertEntity( data: SecretScanningAlertQueryResponse, ) { - if (!data.repository) { - return; - } return createIntegrationEntity({ entityData: { source: data,