/
format-monitor-response.ts
84 lines (79 loc) · 2.55 KB
/
format-monitor-response.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
80
81
82
83
84
import * as _ from '@snyk/lodash';
import chalk from 'chalk';
import * as url from 'url';
import { MonitorResult } from '../../../../lib/types';
import * as config from '../../../../lib/config';
export function formatMonitorOutput(
packageManager,
res: MonitorResult,
options,
projectName?: string,
foundProjectCount?: number,
): string {
const manageUrl = buildManageUrl(res.id, res.org);
const advertiseGradleSubProjectsCount =
packageManager === 'gradle' && !options['gradle-sub-project'];
const advertiseAllProjectsCount =
packageManager !== 'gradle' && !options.allProjects && foundProjectCount;
const issues = res.licensesPolicy ? 'issues' : 'vulnerabilities';
const humanReadableName = projectName
? `${res.path} (${projectName})`
: res.path;
const strOutput =
chalk.bold.white('\nMonitoring ' + humanReadableName + '...\n\n') +
'Explore this snapshot at ' +
res.uri +
'\n\n' +
(advertiseGradleSubProjectsCount && foundProjectCount
? chalk.bold.white(
`Tip: This project has multiple sub-projects (${foundProjectCount}), ` +
'use --all-sub-projects flag to scan all sub-projects.\n\n',
)
: '') +
(advertiseAllProjectsCount && foundProjectCount
? chalk.bold.white(
`Tip: Detected multiple supported manifests (${foundProjectCount}), ` +
'use --all-projects to scan all of them at once.\n\n',
)
: '') +
(res.isMonitored
? 'Notifications about newly disclosed ' +
issues +
' related ' +
'to these dependencies will be emailed to you.\n'
: chalk.bold.red(
'Project is inactive, so notifications are turned ' +
'off.\nActivate this project here: ' +
manageUrl +
'\n\n',
)) +
(res.trialStarted
? chalk.yellow(
"You're over the free plan usage limit, \n" +
'and are now on a free 14-day premium trial.\n' +
'View plans here: ' +
manageUrl +
'\n\n',
)
: '');
return options.json
? JSON.stringify(
_.assign({}, res, {
manageUrl,
packageManager,
}),
)
: strOutput;
}
function buildManageUrl(resId: string, org?: string): string {
const endpoint = url.parse(config.API);
let leader = '';
if (org) {
leader = '/org/' + org;
}
endpoint.pathname = leader + '/manage';
const manageUrl = url.format(endpoint);
// TODO: what was this meant to do?
endpoint.pathname = leader + '/monitor/' + resId;
return manageUrl;
}