Skip to content

Commit

Permalink
Merge pull request #2063 from snyk/feat/snyk-fix-meta
Browse files Browse the repository at this point in the history
feat: send back meta on fixed, failed & total issues
  • Loading branch information
lili2311 authored Jun 28, 2021
2 parents 5e689c9 + f857d9a commit d346d89
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 6 deletions.
30 changes: 25 additions & 5 deletions packages/snyk-fix/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,16 @@ import { loadPlugin } from './plugins/load-plugin';
import { FixHandlerResultByPlugin } from './plugins/types';
import { partitionByVulnerable } from './partition-by-vulnerable';

import { EntityToFix, ErrorsByEcoSystem, FixedMeta, FixOptions } from './types';
import {
EntityToFix,
ErrorsByEcoSystem,
FixedMeta,
FixOptions,
TestResult,
} from './types';
import { convertErrorToUserMessage } from './lib/errors/error-to-user-message';
import { getTotalIssueCount } from './lib/issues/total-issues-count';
import { hasFixableIssues } from './lib/issues/fixable-issues';
export { EntityToFix } from './types';

const debug = debugLib('snyk-fix:main');
Expand Down Expand Up @@ -104,13 +112,25 @@ export function groupEntitiesPerScanType(

export function extractMeta(
resultsByPlugin: FixHandlerResultByPlugin,
exceptionsByScanType: ErrorsByEcoSystem,
exceptions: ErrorsByEcoSystem,
): FixedMeta {
const failed = outputFormatter.calculateFailed(
const testResults: TestResult[] = outputFormatter.getTestResults(
resultsByPlugin,
exceptionsByScanType,
exceptions,
);
const issueData = testResults.map((i) => i.issuesData);

const failed = outputFormatter.calculateFailed(resultsByPlugin, exceptions);
const fixed = outputFormatter.calculateFixed(resultsByPlugin);
const totalIssueCount = getTotalIssueCount(issueData);
const { count: fixableCount } = hasFixableIssues(testResults);
const fixedIssueCount = outputFormatter.calculateFixedIssues(resultsByPlugin);

return { fixed, failed };
return {
fixed,
failed,
totalIssues: totalIssueCount,
fixableIssues: fixableCount,
fixedIssues: fixedIssueCount,
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,7 @@ export function generateIssueSummary(
return `\n${PADDING_SPACE}${totalIssues}${PADDING_SPACE}${fixableIssues}${PADDING_SPACE}${fixedIssuesSummary}`;
}

function getTestResults(
export function getTestResults(
resultsByPlugin: FixHandlerResultByPlugin,
exceptionsByScanType: ErrorsByEcoSystem,
): TestResult[] {
Expand Down
3 changes: 3 additions & 0 deletions packages/snyk-fix/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -244,4 +244,7 @@ export interface FixOptions {
export interface FixedMeta {
fixed: number;
failed: number;
fixableIssues: number;
fixedIssues: number;
totalIssues: number;
}
9 changes: 9 additions & 0 deletions packages/snyk-fix/test/unit/__snapshots__/fix.spec.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,10 @@ Summary:
Tip: Re-run in debug mode to see more information: DEBUG=*snyk* <COMMAND>. If the issue persists contact [email protected]",
"meta": Object {
"failed": 1,
"fixableIssues": 1,
"fixed": 0,
"fixedIssues": 0,
"totalIssues": 1,
},
"results": Object {},
}
Expand All @@ -108,7 +111,10 @@ Summary:
",
"meta": Object {
"failed": 0,
"fixableIssues": 1,
"fixed": 1,
"fixedIssues": 1,
"totalIssues": 1,
},
"results": Object {
"python": Object {
Expand Down Expand Up @@ -211,7 +217,10 @@ Summary:
",
"meta": Object {
"failed": 0,
"fixableIssues": 2,
"fixed": 2,
"fixedIssues": 2,
"totalIssues": 2,
},
"results": Object {
"python": Object {
Expand Down

0 comments on commit d346d89

Please sign in to comment.