-
Notifications
You must be signed in to change notification settings - Fork 532
/
format-test-meta.ts
79 lines (76 loc) · 2.39 KB
/
format-test-meta.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
import chalk from 'chalk';
import { rightPadWithSpaces } from '../../../../lib/right-pad';
import { TestOptions, Options } from '../../../../lib/types';
import { TestResult } from '../../../../lib/snyk-test/legacy';
import { IacTestResult } from '../../../../lib/snyk-test/iac-test-result';
export function formatTestMeta(
res: TestResult | IacTestResult,
options: Options & TestOptions,
): string {
const padToLength = 19; // chars to align
const packageManager = res.packageManager || options.packageManager;
const targetFile = res.targetFile || res.displayTargetFile || options.file;
const openSource = res.isPrivate ? 'no' : 'yes';
const meta = [
chalk.bold(rightPadWithSpaces('Organization: ', padToLength)) + res.org,
chalk.bold(rightPadWithSpaces('Package manager: ', padToLength)) +
packageManager,
];
if (targetFile) {
meta.push(
chalk.bold(rightPadWithSpaces('Target file: ', padToLength)) + targetFile,
);
}
if (res.projectName) {
meta.push(
chalk.bold(rightPadWithSpaces('Project name: ', padToLength)) +
res.projectName,
);
}
if (options.docker) {
meta.push(
chalk.bold(rightPadWithSpaces('Docker image: ', padToLength)) +
options.path,
);
} else {
meta.push(
chalk.bold(rightPadWithSpaces('Open source: ', padToLength)) + openSource,
);
meta.push(
chalk.bold(rightPadWithSpaces('Project path: ', padToLength)) +
options.path,
);
}
if (res.payloadType !== 'k8sconfig') {
const legacyRes: TestResult = res as TestResult;
if (legacyRes.docker && legacyRes.docker.baseImage) {
meta.push(
chalk.bold(rightPadWithSpaces('Base image: ', padToLength)) +
legacyRes.docker.baseImage,
);
}
if (legacyRes.filesystemPolicy) {
meta.push(
chalk.bold(rightPadWithSpaces('Local Snyk policy: ', padToLength)) +
chalk.green('found'),
);
if (
legacyRes.ignoreSettings &&
legacyRes.ignoreSettings.disregardFilesystemIgnores
) {
meta.push(
chalk.bold(
rightPadWithSpaces('Local Snyk policy ignored: ', padToLength),
) + chalk.red('yes'),
);
}
}
if (legacyRes.licensesPolicy) {
meta.push(
chalk.bold(rightPadWithSpaces('Licenses: ', padToLength)) +
chalk.green('enabled'),
);
}
}
return meta.join('\n');
}