Skip to content

Commit

Permalink
feat: fix individual file with provenance
Browse files Browse the repository at this point in the history
  • Loading branch information
lili2311 committed Mar 29, 2021
1 parent 7afa49c commit 6e84322
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
Expand Up @@ -20,7 +20,8 @@ export async function extractProvenance(
fileName: string,
provenance: PythonProvenance = {},
): Promise<PythonProvenance> {
const requirementsTxt = await workspace.readFile(path.join(dir, fileName));
const requirementsFileName = path.join(dir, fileName);
const requirementsTxt = await workspace.readFile(requirementsFileName);
provenance = {
...provenance,
[fileName]: parseRequirementsFile(requirementsTxt),
Expand Down
@@ -1,4 +1,5 @@
import * as debugLib from 'debug';
import * as pathLib from 'path';

import {
EntityToFix,
Expand All @@ -11,7 +12,7 @@ import { MissingRemediationDataError } from '../../../../lib/errors/missing-reme
import { MissingFileNameError } from '../../../../lib/errors/missing-file-name';
import { partitionByFixable } from './is-supported';
import { NoFixesCouldBeAppliedError } from '../../../../lib/errors/no-fixes-applied';
import { parseRequirementsFile } from './update-dependencies/requirements-file-parser';
import { extractProvenance } from './extract-version-provenance';

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

Expand Down Expand Up @@ -53,17 +54,19 @@ export async function fixIndividualRequirementsTxt(
if (!fileName) {
throw new MissingFileNameError();
}
const requirementsTxt = await entity.workspace.readFile(fileName);
const requirementsData = parseRequirementsFile(requirementsTxt);

const { dir, base } = pathLib.parse(fileName);
const versionProvenance = await extractProvenance(
entity.workspace,
dir,
base,
);
// TODO: allow handlers per fix type (later also strategies or combine with strategies)
const { updatedManifest, changes } = updateDependencies(
requirementsData,
versionProvenance[base],
remediationData.pin,
);

// TODO: do this with the changes now that we only return new
if (updatedManifest === requirementsTxt) {
if (!changes.length) {
debug('Manifest has not changed!');
throw new NoFixesCouldBeAppliedError();
}
Expand Down

0 comments on commit 6e84322

Please sign in to comment.