Skip to content

Commit

Permalink
fix: --target-name bug
Browse files Browse the repository at this point in the history
  • Loading branch information
YairZ101 committed Aug 25, 2022
1 parent c3095cf commit 3431f79
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export async function shareResults({
policy: Policy | undefined;
tags?: Tag[];
attributes?: ProjectAttributes;
options?: IaCTestFlags;
options: IaCTestFlags;
meta: IacOutputMeta;
}): Promise<ShareResultsOutput> {
const scanResults = results.map((result) =>
Expand Down
4 changes: 2 additions & 2 deletions src/lib/ecosystems/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export interface ContainerTarget {
image: string;
}

export interface UnknownTarget {
export interface NamedTarget extends GitTarget {
name: string; // Should be equal to the project name
}

Expand All @@ -30,7 +30,7 @@ export interface ScanResult {
findings?: Finding[];
name?: string;
policy?: string;
target?: GitTarget | ContainerTarget | UnknownTarget;
target?: GitTarget | ContainerTarget | NamedTarget;
analytics?: Analytics[];
targetReference?: string;
}
Expand Down
13 changes: 8 additions & 5 deletions src/lib/iac/envelope-formatters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@ import {
IaCTestFlags,
PolicyMetadata,
} from '../../cli/commands/test/iac/local-execution/types';
import { ScanResult } from '../ecosystems/types';
import { GitTarget, NamedTarget, ScanResult } from '../ecosystems/types';
import { Policy } from '../policy/find-and-load-policy';
import { IacOutputMeta } from '../types';

export function convertIacResultToScanResult(
iacResult: IacShareResultsFormat,
policy: Policy | undefined,
meta: IacOutputMeta,
options?: IaCTestFlags,
options: IaCTestFlags,
): ScanResult {
return {
identity: {
Expand All @@ -26,15 +26,18 @@ export function convertIacResultToScanResult(
};
}),
name: iacResult.projectName,
target: buildTarget(meta),
target: buildTarget(meta, options),
policy: policy?.toString() ?? '',
targetReference: options?.['target-reference'],
};
}

function buildTarget(meta: IacOutputMeta) {
function buildTarget(
meta: IacOutputMeta,
options: IaCTestFlags,
): NamedTarget | GitTarget {
if (meta.gitRemoteUrl) {
return { remoteUrl: meta.gitRemoteUrl };
return { remoteUrl: meta.gitRemoteUrl, name: options['target-name'] };
}
return { name: meta.projectName };
}
4 changes: 2 additions & 2 deletions src/lib/polling/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
import {
GitTarget,
ContainerTarget,
UnknownTarget,
NamedTarget,
MonitorDependenciesResponse,
} from '../ecosystems/types';

Expand Down Expand Up @@ -49,7 +49,7 @@ export interface ResolutionMeta {
identity: {
type: string;
};
target?: GitTarget | ContainerTarget | UnknownTarget;
target?: GitTarget | ContainerTarget | NamedTarget;
policy?: string;
targetReference?: string;
}
3 changes: 3 additions & 0 deletions test/jest/unit/iac/cli-share-results.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ describe('CLI Share Results', () => {
orgName: 'org-name',
gitRemoteUrl: 'http://github.com/snyk/cli.git',
},
options: {},
});

expect(envelopeFormattersSpy.mock.calls.length).toBe(2);
Expand All @@ -69,6 +70,7 @@ describe('CLI Share Results', () => {
orgName: 'org-name',
gitRemoteUrl: 'http://github.com/snyk/cli.git',
},
options: {},
});

expect(envelopeFormattersSpy.mock.calls.length).toBe(2);
Expand Down Expand Up @@ -139,6 +141,7 @@ describe('CLI Share Results', () => {
orgName: 'org-name',
gitRemoteUrl: 'http://github.com/snyk/cli.git',
},
options: {},
});

expect(requestSpy.mock.calls.length).toBe(1);
Expand Down

0 comments on commit 3431f79

Please sign in to comment.