Skip to content

Commit

Permalink
feat: display dry run mode warning
Browse files Browse the repository at this point in the history
- update the retry message to be white with `Tip:` at the beginning
  • Loading branch information
lili2311 committed Jun 22, 2021
1 parent fbc5947 commit 1a13190
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 12 deletions.
2 changes: 1 addition & 1 deletion packages/snyk-fix/src/lib/errors/common.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export const reTryMessage =
'Re-run in debug mode to see more information: DEBUG=*snyk* <COMMAND>';
'Tip: Re-run in debug mode to see more information: DEBUG=*snyk* <COMMAND>';
export const contactSupportMessage =
'If the issue persists contact support@snyk.io';
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,11 @@ export async function showResultsSummary(
const {
summary: overallSummary,
count: changedCount,
} = generateFixedAndFailedSummary(resultsByPlugin, exceptionsByScanType);
} = generateFixedAndFailedSummary(
resultsByPlugin,
exceptionsByScanType,
options,
);

const vulnsSummary = generateIssueSummary(
resultsByPlugin,
Expand All @@ -36,7 +40,7 @@ export async function showResultsSummary(
const fixedIssuesSummary = `${chalk.bold(
calculateFixedIssues(resultsByPlugin),
)} fixed issues`;
const getHelpText = chalk.red(`\n${reTryMessage}. ${contactSupportMessage}`);
const getHelpText = `\n${reTryMessage}. ${contactSupportMessage}`;

const fixSummary = `\n${successfulFixesSummary}${
unresolvedSummary ? `\n\n${unresolvedSummary}` : ''
Expand Down Expand Up @@ -128,14 +132,19 @@ export function generateUnresolvedSummary(
export function generateFixedAndFailedSummary(
resultsByPlugin: FixHandlerResultByPlugin,
exceptionsByScanType: ErrorsByEcoSystem,
options: FixOptions,
): { summary: string; count: number } {
const sectionTitle = 'Summary:';
const formattedTitleHeader = `${chalk.bold(sectionTitle)}`;
const fixed = calculateFixed(resultsByPlugin);
const failed = calculateFailed(resultsByPlugin, exceptionsByScanType);

const dryRunText = options.dryRun
? chalk.hex('#EDD55E')(
`${PADDING_SPACE}Command run in dry run mode. Fixes are not be applied.\n`,
)
: '';
return {
summary: `${formattedTitleHeader}\n\n${PADDING_SPACE}${chalk.bold.red(
summary: `${formattedTitleHeader}\n\n${dryRunText}${PADDING_SPACE}${chalk.bold.red(
failed,
)} items were not fixed\n${PADDING_SPACE}${chalk.green.bold(
fixed,
Expand Down
3 changes: 2 additions & 1 deletion packages/snyk-fix/test/unit/__snapshots__/fix.spec.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ Summary:
0 fixed issues
Re-run in debug mode to see more information: DEBUG=*snyk* <COMMAND>. If the issue persists contact support@snyk.io",
Tip: Re-run in debug mode to see more information: DEBUG=*snyk* <COMMAND>. If the issue persists contact support@snyk.io",
"meta": Object {
"failed": 1,
"fixed": 0,
Expand Down Expand Up @@ -201,6 +201,7 @@ Successful fixes:
Summary:
Command run in dry run mode. Fixes are not be applied.
0 items were not fixed
2 items were successfully fixed
2 total issues: 2 High
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ exports[`formatIssueCountBySeverity all vuln severities present 1`] = `"1 Critic
exports[`generateFixedAndFailedSummary has failed only 1`] = `
"Summary:
Command run in dry run mode. Fixes are not be applied.
1 items were not fixed
0 items were successfully fixed"
`;
Expand All @@ -32,6 +33,7 @@ exports[`generateFixedAndFailedSummary has fixed only 1`] = `
exports[`generateFixedAndFailedSummary has skipped & failed & plugin errors 1`] = `
"Summary:
Command run in dry run mode. Fixes are not be applied.
2 items were not fixed
1 items were successfully fixed"
`;
Expand Down Expand Up @@ -85,7 +87,7 @@ Summary:
1 fixed issues
Re-run in debug mode to see more information: DEBUG=*snyk* <COMMAND>. If the issue persists contact support@snyk.io"
Tip: Re-run in debug mode to see more information: DEBUG=*snyk* <COMMAND>. If the issue persists contact support@snyk.io"
`;
exports[`showResultsSummary has unresolved only 1`] = `
Expand All @@ -106,5 +108,5 @@ Summary:
0 fixed issues
Re-run in debug mode to see more information: DEBUG=*snyk* <COMMAND>. If the issue persists contact support@snyk.io"
Tip: Re-run in debug mode to see more information: DEBUG=*snyk* <COMMAND>. If the issue persists contact support@snyk.io"
`;
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ describe('generateFixedAndFailedSummary', () => {
skipped: [],
},
};
const res = await generateFixedAndFailedSummary(resultsByPlugin, {});
const res = await generateFixedAndFailedSummary(resultsByPlugin, {}, {});
expect(stripAnsi(res.summary)).toMatchSnapshot();
});

Expand Down Expand Up @@ -77,7 +77,7 @@ describe('generateFixedAndFailedSummary', () => {
skipped: [],
},
};
const res = await generateFixedAndFailedSummary(resultsByPlugin, {});
const res = await generateFixedAndFailedSummary(resultsByPlugin, {}, {});
expect(stripAnsi(res.summary)).toMatchSnapshot();
expect(res.count).toEqual(1);
});
Expand All @@ -100,7 +100,11 @@ describe('generateFixedAndFailedSummary', () => {
skipped: [],
},
};
const res = await generateFixedAndFailedSummary(resultsByPlugin, {});
const res = await generateFixedAndFailedSummary(
resultsByPlugin,
{},
{ dryRun: true },
);
expect(stripAnsi(res.summary)).toMatchSnapshot();
expect(res.count).toEqual(1);
});
Expand Down Expand Up @@ -146,7 +150,11 @@ describe('generateFixedAndFailedSummary', () => {
],
},
};
const res = await generateFixedAndFailedSummary(resultsByPlugin, {});
const res = await generateFixedAndFailedSummary(
resultsByPlugin,
{},
{ dryRun: true },
);
expect(stripAnsi(res.summary)).toMatchSnapshot();
expect(res.count).toEqual(3);
});
Expand Down

0 comments on commit 1a13190

Please sign in to comment.