diff --git a/src/generate-target-id.ts b/src/generate-target-id.ts index 88101531..c189f712 100644 --- a/src/generate-target-id.ts +++ b/src/generate-target-id.ts @@ -1,7 +1,7 @@ import * as _ from 'lodash'; import { targetProps } from './common'; -import { Target } from './lib/types'; +import type { Target } from './lib/types'; export function generateTargetId( orgId: string, diff --git a/src/lib/api/import/index.ts b/src/lib/api/import/index.ts index d82c704a..2b8dddae 100644 --- a/src/lib/api/import/index.ts +++ b/src/lib/api/import/index.ts @@ -12,7 +12,11 @@ import { getLoggingPath } from '../../get-logging-path'; import { logFailedImports } from '../../../loggers/log-failed-imports'; import { logImportJobsPerOrg } from '../../../loggers/log-import-jobs'; import { getConcurrentImportsNumber } from '../../get-concurrent-imports-number'; -import { FAILED_LOG_NAME, targetPropsWithId } from '../../../common'; +import { + FAILED_LOG_NAME, + targetProps, + targetPropsWithId, +} from '../../../common'; import { requestWithRateLimitHandling } from './request-with-rate-limit'; const debug = debugLib('snyk:api-import'); @@ -43,7 +47,9 @@ export async function importTarget( } try { const body = { - target: _.pick(target, ...targetPropsWithId), + target: isGitlabTarget(target) + ? _.pick(target, ...targetPropsWithId) + : _.pick(target, ...targetProps), files, exclusionGlobs, }; @@ -152,3 +158,16 @@ export async function importTargets( ); return _.uniq(pollingUrls); } + +function isGitlabTarget(target: Target): boolean { + const keys = Object.keys(target); + + if (keys.length !== 2) { + return false; + } + if (keys.find((k) => k === 'id') && keys.find((k) => k === 'branch')) { + return true; + } + + return false; +}