Skip to content

Commit

Permalink
fix: strip id from non Gitlab targets
Browse files Browse the repository at this point in the history
  • Loading branch information
lili2311 committed Dec 8, 2022
1 parent afea991 commit 38f5af8
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/generate-target-id.ts
Original file line number Diff line number Diff line change
@@ -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,
Expand Down
23 changes: 21 additions & 2 deletions src/lib/api/import/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down Expand Up @@ -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,
};
Expand Down Expand Up @@ -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;
}

0 comments on commit 38f5af8

Please sign in to comment.