Skip to content

Commit

Permalink
feat: output the fixSummary provided by @snyk/fix
Browse files Browse the repository at this point in the history
  • Loading branch information
lili2311 committed Mar 12, 2021
1 parent fef8c55 commit fa8b7ff
Show file tree
Hide file tree
Showing 7 changed files with 39 additions and 29 deletions.
7 changes: 5 additions & 2 deletions packages/snyk-fix/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,11 @@ export async function fix(
const fixed = outputFormatter.calculateFixed(resultsByPlugin);

spinner.start();
spinner.stopAndPersist({ text: 'Done', symbol: chalk.green('✔') });
spinner.stopAndPersist({ text: `\n${fixSummary}` });
spinner.stopAndPersist({
text: 'Done',
symbol: fixed === 0 ? chalk.red('✖') : chalk.green('✔') ,
});

return {
results: resultsByPlugin,
exceptions: exceptionsByScanType,
Expand Down
42 changes: 25 additions & 17 deletions packages/snyk-fix/test/unit/__snapshots__/fix.spec.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

exports[`Error handling Snyk fix returns error when called with unsupported type 1`] = `
Object {
"exceptionsByScanType": Object {
"exceptions": Object {
"npm": Object {
"originals": Array [
Object {
Expand Down Expand Up @@ -57,39 +57,47 @@ Object {
"userMessage": "npm is not supported.",
},
},
"fixSummary": "[31m✖ No successful fixes[39m
"fixSummary": "✖ No successful fixes
[1mUnresolved items:[22m
Unresolved items:
package.json
[31m✖[39m [31mnpm is not supported.[39m
npm is not supported.
[1mSummary:[22m
Summary:
1 items were not fixed
0 items were successfully fixed",
"resultsByPlugin": Object {},
1 items were not fixed
0 items were successfully fixed",
"meta": Object {
"failed": 1,
"fixed": 0,
},
"results": Object {},
}
`;

exports[`Snyk fix Snyk fix returns results for supported & unsupported type 1`] = `
Object {
"exceptionsByScanType": Object {},
"fixSummary": "[1mSuccessful fixes:[22m
"exceptions": Object {},
"fixSummary": "Successful fixes:
requirements.txt
[32m✔[39m Pinned django from 1.6.1 to 2.0.1
Pinned django from 1.6.1 to 2.0.1
[1mUnresolved items:[22m
Unresolved items:
Pipfile
[31m✖[39m [31mPipfile is not supported[39m
Pipfile is not supported
[1mSummary:[22m
Summary:
1 items were not fixed
1 items were successfully fixed",
"resultsByPlugin": Object {
1 items were not fixed
1 items were successfully fixed",
"meta": Object {
"failed": 1,
"fixed": 1,
},
"results": Object {
"python": Object {
"failed": Array [],
"skipped": Array [
Expand Down
9 changes: 6 additions & 3 deletions src/cli/commands/fix/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,12 @@ async function fix(...args: MethodArgs): Promise<string> {
debug(
`Organization has ${snykFixFeatureFlag} feature flag enabled for experimental Snyk fix functionality`,
);
await snykFix.fix(results);
// TODO: what is being returned if anything?
return '';
const { fixSummary, meta } = await snykFix.fix(results);

if (meta.fixed === 0) {
throw new Error(fixSummary);
}
return fixSummary;
}

/* @deprecated
Expand Down
5 changes: 0 additions & 5 deletions src/cli/commands/test/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,15 +51,10 @@ import {

import * as iacLocalExecution from './iac-local-execution';
import { validateCredentials } from './validate-credentials';
<<<<<<< HEAD
import { generateSnykTestError } from './generate-snyk-test-error';
import { validateTestOptions } from './validate-test-options';
import { setDefaultTestOptions } from './set-default-test-options';
=======
>>>>>>> feat: introduce `snyk fix` CLI command
import { processCommandArgs } from '../process-command-args';
import { formatTestError } from './format-test-error';
import { validateTestOptions } from './validate-test-options';

const debug = Debug('snyk-test');
const SEPARATOR = '\n-------------------------------------------------------\n';
Expand Down
2 changes: 1 addition & 1 deletion src/lib/errors/command-not-supported.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export class CommandNotSupportedError extends CustomError {
this.command = command;
this.org = org;

this.userMessage = `\`${command}\`' is not supported ${
this.userMessage = `\`${command}\` is not supported ${
org ? `for org '${org}'` : ''
}`;
}
Expand Down
2 changes: 1 addition & 1 deletion src/lib/errors/not-supported-by-ecosystem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@ export class FeatureNotSupportedByEcosystemError extends CustomError {
this.code = 422;
this.feature = feature;

this.userMessage = `'${feature}' is not supported for ecosystem '${ecosystem}'`;
this.userMessage = `\`${feature}\` is not supported for ecosystem '${ecosystem}'`;
}
}
1 change: 1 addition & 0 deletions test/acceptance/workspaces/pip-app-custom/base.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Jinja2==2.7.2

0 comments on commit fa8b7ff

Please sign in to comment.