Skip to content

Commit

Permalink
feat: improve snyk fix output
Browse files Browse the repository at this point in the history
- bump the @snyk/fix version to one that includes full
targetFile paths in all output
- swap out the spinner icon & fix a spinner not clearing when
multuple paths tested
  • Loading branch information
lili2311 committed Apr 14, 2021
1 parent 9e97a18 commit 34c9a60
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 9 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@
"@snyk/cloud-config-parser": "^1.9.2",
"@snyk/code-client": "3.4.0",
"@snyk/dep-graph": "^1.27.1",
"@snyk/fix": "1.526.0",
"@snyk/fix": "1.539.0",
"@snyk/gemfile": "1.2.0",
"@snyk/graphlib": "^2.1.9-patch.3",
"@snyk/inquirer": "^7.3.3-patch",
Expand Down
4 changes: 0 additions & 4 deletions packages/snyk-fix/src/plugins/python/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,6 @@ export async function pythonFix(
results.failed.push(
...projectsToFix.map((p) => ({ original: p, error: e })),
);
spinner.stopAndPersist({
text: processingMessage,
symbol: chalk.green('✔'),
});
}
spinner.stopAndPersist({
text: processingMessage,
Expand Down
23 changes: 20 additions & 3 deletions src/cli/commands/fix/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import { setDefaultTestOptions } from '../test/set-default-test-options';
import { validateFixCommandIsSupported } from './validate-fix-command-is-supported';
import { Options, TestOptions } from '../../../lib/types';
import { getDisplayPath } from './get-display-path';
import chalk from 'chalk';

const debug = Debug('snyk-fix');
const snykFixFeatureFlag = 'cliSnykFix';
Expand Down Expand Up @@ -71,9 +72,12 @@ async function runSnykTestLegacy(

for (const path of paths) {
let displayPath = path;
const spinnerMessage = `Running \`snyk test\` for ${displayPath}`;

try {
displayPath = getDisplayPath(path);
stdOutSpinner.info(`Running \`snyk test\` for ${displayPath}`);
stdOutSpinner.text = spinnerMessage;
stdOutSpinner.render();
// Create a copy of the options so a specific test can
// modify them i.e. add `options.file` etc. We'll need
// these options later.
Expand All @@ -96,10 +100,23 @@ async function runSnykTestLegacy(
);
const newRes = convertLegacyTestResultToFixEntities(testResults, path);
results.push(...newRes);
stdOutSpinner.stopAndPersist({
text: spinnerMessage,
symbol: '\n►',
});
} catch (error) {
const testError = formatTestError(error);
const userMessage = `Test for ${displayPath} failed with error: ${testError.message}.\nRun \`snyk test ${displayPath} -d\` for more information.`;
stdErrSpinner.fail(userMessage);
const userMessage =
chalk.red(`Failed! ${testError.message}.`) +
`\n Tip: run \`snyk test ${displayPath} -d\` for more information.`;
stdOutSpinner.stopAndPersist({
text: spinnerMessage,
symbol: '\n►',
});
stdErrSpinner.stopAndPersist({
text: userMessage,
symbol: chalk.red(' '),
});
debug(userMessage);
}
}
Expand Down
3 changes: 2 additions & 1 deletion src/cli/commands/fix/validate-fix-command-is-supported.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,13 @@ export async function validateFixCommandIsSupported(
options.org,
);

debug('Feature flag check returned: ', snykFixSupported);

if (snykFixSupported.code === 401 || snykFixSupported.code === 403) {
throw AuthFailedError(snykFixSupported.error, snykFixSupported.code);
}

if (!snykFixSupported.ok) {
debug('Feature flag check returned: ', snykFixSupported);
throw new CommandNotSupportedError('snyk fix', options.org || undefined);
}

Expand Down

0 comments on commit 34c9a60

Please sign in to comment.