From c65cfebb1b039a37294e60442b162afca9a4532b Mon Sep 17 00:00:00 2001 From: Roshick Date: Wed, 6 Mar 2024 10:13:42 +0100 Subject: [PATCH] fix: ignore missing targets when multiple orgs are used and rename display name attribute to fit --- src/api/index.ts | 6 ++++-- src/types/targetsTypes.ts | 2 +- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/api/index.ts b/src/api/index.ts index 76db2fb..a120f74 100644 --- a/src/api/index.ts +++ b/src/api/index.ts @@ -378,12 +378,14 @@ export class SnykApiClient implements SnykApi { } const jsonResponse = await response.json(); return jsonResponse.data as ProjectsData[]; - } else { + } else if (!ignoreMissing) { throw new Error( `No target IDs found in org ${orgId} for the targets [${repoName.join( "," )}].` ); + } else { + return []; } } @@ -452,7 +454,7 @@ export class SnykApiClient implements SnykApi { const targetsList = await targetResponse.json(); const targetsListData = targetsList.data as TargetData[]; targetId = targetsListData.find((target) => { - return target.attributes.displayName === targetIdentifier; + return target.attributes.display_name === targetIdentifier; })?.id; if (!targetId) { throw new Error( diff --git a/src/types/targetsTypes.ts b/src/types/targetsTypes.ts index a0a20c3..135e86d 100644 --- a/src/types/targetsTypes.ts +++ b/src/types/targetsTypes.ts @@ -5,7 +5,7 @@ export interface TargetDataAttributes { * @type {string} * @memberof TargetDataAttributes */ - displayName?: string; + display_name?: string; /** * The URL for the resource. We do not use this as part of our representation of the identity of the target, as it can be changed externally to Snyk We are reliant on individual integrations providing us with this value. Currently it is only provided by the CLI * @type {string}