Skip to content

Commit

Permalink
Merge pull request #2016 from snyk/fix/partition-by-fixable
Browse files Browse the repository at this point in the history
Fix: partition Python projects by fixable earlier on in Snyk fix flow
  • Loading branch information
lili2311 committed Jun 11, 2021
2 parents 8b3d14a + b0a45f8 commit 25acaff
Show file tree
Hide file tree
Showing 7 changed files with 13 additions and 18 deletions.
2 changes: 1 addition & 1 deletion packages/snyk-fix/package.json
Expand Up @@ -40,7 +40,7 @@
"license": "Apache-2.0",
"dependencies": {
"@snyk/dep-graph": "^1.21.0",
"@snyk/fix-pipenv-pipfile": "0.4.3",
"@snyk/fix-pipenv-pipfile": "0.5.3",
"chalk": "4.1.1",
"debug": "^4.3.1",
"lodash.groupby": "4.6.0",
Expand Down
1 change: 1 addition & 0 deletions packages/snyk-fix/src/lib/errors/custom-error.ts
Expand Up @@ -16,4 +16,5 @@ export enum ERROR_CODES {
MissingFileName = 'G12',
FailedToParseManifest = 'G13',
CommandFailed = 'G14',
NoFixesCouldBeApplied = 'G15',
}
7 changes: 0 additions & 7 deletions packages/snyk-fix/src/lib/errors/invalid-workspace.ts

This file was deleted.

Expand Up @@ -4,7 +4,7 @@ export class MissingRemediationDataError extends CustomError {
public constructor() {
super(
'Remediation data is required to apply fixes',
ERROR_CODES.UnsupportedTypeError,
ERROR_CODES.MissingRemediationData,
);
}
}
2 changes: 1 addition & 1 deletion packages/snyk-fix/src/lib/errors/no-fixes-applied.ts
Expand Up @@ -2,6 +2,6 @@ import { CustomError, ERROR_CODES } from './custom-error';

export class NoFixesCouldBeAppliedError extends CustomError {
public constructor() {
super('No fixes could be applied', ERROR_CODES.UnsupportedTypeError);
super('No fixes could be applied', ERROR_CODES.NoFixesCouldBeApplied);
}
}
Expand Up @@ -13,7 +13,6 @@ import {
} from '../../../../types';
import { FixedCache, PluginFixResponse } from '../../../types';
import { updateDependencies } from './update-dependencies';
import { partitionByFixable } from './../is-supported';
import { NoFixesCouldBeAppliedError } from '../../../../lib/errors/no-fixes-applied';
import { extractProvenance } from './extract-version-provenance';
import {
Expand All @@ -28,19 +27,16 @@ import { formatDisplayName } from '../../../../lib/output-formatters/format-disp
const debug = debugLib('snyk-fix:python:requirements.txt');

export async function pipRequirementsTxt(
entities: EntityToFix[],
fixable: EntityToFix[],
options: FixOptions,
): Promise<PluginFixResponse> {
debug(`Preparing to fix ${entities.length} Python requirements.txt projects`);
debug(`Preparing to fix ${fixable.length} Python requirements.txt projects`);
const handlerResult: PluginFixResponse = {
succeeded: [],
failed: [],
skipped: [],
};

const { fixable, skipped: notFixable } = await partitionByFixable(entities);
handlerResult.skipped.push(...notFixable);

const ordered = sortByDirectory(fixable);
let fixedFilesCache: FixedCache = {};
for (const dir of Object.keys(ordered)) {
Expand Down
9 changes: 7 additions & 2 deletions packages/snyk-fix/src/plugins/python/index.ts
Expand Up @@ -8,6 +8,7 @@ import { loadHandler } from './load-handler';
import { SUPPORTED_HANDLER_TYPES } from './supported-handler-types';
import { mapEntitiesPerHandlerType } from './map-entities-per-handler-type';
import chalk = require('chalk');
import { partitionByFixable } from './handlers/is-supported';

const debug = debugLib('snyk-fix:python');

Expand Down Expand Up @@ -51,10 +52,14 @@ export async function pythonFix(

try {
const handler = loadHandler(projectType as SUPPORTED_HANDLER_TYPES);
const { failed, skipped, succeeded } = await handler(
// drop unsupported Python entities early so only potentially fixable items get
// attempted to be fixed
const { fixable, skipped: notFixable } = await partitionByFixable(
projectsToFix,
options,
);
results.skipped.push(...notFixable);

const { failed, skipped, succeeded } = await handler(fixable, options);
results.failed.push(...failed);
results.skipped.push(...skipped);
results.succeeded.push(...succeeded);
Expand Down

0 comments on commit 25acaff

Please sign in to comment.