"Fossies" - the Fresh Open Source Software Archive 
Member "cli-1.1260.0/packages/snyk-fix/src/plugins/python/handlers/attempted-changes-summary.ts" (4 Dec 2023, 2023 Bytes) of package /linux/misc/snyk-cli-1.1260.0.tar.gz:
As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) TypeScript source code syntax highlighting (style:
standard) with prefixed line numbers and
code folding option.
Alternatively you can here
view or
download the uninterpreted source code file.
1 import {
2 DependencyPins,
3 FixChangesError,
4 FixChangesSuccess,
5 FixChangesSummary,
6 } from '../../../types';
7
8 export function generateFailedChanges(
9 attemptedUpdates: string[],
10 pins: DependencyPins,
11 error: Error,
12 command?: string,
13 ): FixChangesError[] {
14 const changes: FixChangesError[] = [];
15 for (const pkgAtVersion of Object.keys(pins)) {
16 const pin = pins[pkgAtVersion];
17 if (
18 !attemptedUpdates
19 .map((update) => update.replace('==', '@'))
20 .includes(pin.upgradeTo)
21 ) {
22 continue;
23 }
24 const updatedMessage = pin.isTransitive ? 'pin' : 'upgrade';
25 const newVersion = pin.upgradeTo.split('@')[1];
26 const [pkgName, version] = pkgAtVersion.split('@');
27
28 changes.push({
29 success: false,
30 reason: error.message,
31 userMessage: `Failed to ${updatedMessage} ${pkgName} from ${version} to ${newVersion}`,
32 tip: command ? `Try running \`${command}\`` : undefined,
33 issueIds: pin.vulns,
34 from: pkgAtVersion,
35 to: `${pkgName}@${newVersion}`,
36 });
37 }
38 return changes;
39 }
40
41 export function generateSuccessfulChanges(
42 appliedUpgrades: string[],
43 pins: DependencyPins,
44 ): FixChangesSuccess[] {
45 const changes: FixChangesSuccess[] = [];
46 for (const pkgAtVersion of Object.keys(pins)) {
47 const pin = pins[pkgAtVersion];
48 if (
49 !appliedUpgrades
50 .map((upgrade) => upgrade.replace('==', '@'))
51 .includes(pin.upgradeTo)
52 ) {
53 continue;
54 }
55 const updatedMessage = pin.isTransitive ? 'Pinned' : 'Upgraded';
56 const newVersion = pin.upgradeTo.split('@')[1];
57 const [pkgName, version] = pkgAtVersion.split('@');
58
59 changes.push({
60 success: true,
61 userMessage: `${updatedMessage} ${pkgName} from ${version} to ${newVersion}`,
62 issueIds: pin.vulns,
63 from: pkgAtVersion,
64 to: `${pkgName}@${newVersion}`,
65 });
66 }
67 return changes;
68 }
69
70 export function isSuccessfulChange(
71 change: FixChangesSummary,
72 ): change is FixChangesError {
73 return change.success === true;
74 }