-
Notifications
You must be signed in to change notification settings - Fork 556
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: sequential fix #2252
Merged
Merged
feat: sequential fix #2252
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
f423a71
feat: support sequentially applying upgrades for Poetry
lili2311 7e09ac5
refactor: split out Poetry fix functions into files
lili2311 8fdc9b7
refactor: split out Pipenv fix functions into files
lili2311 d820026
fix: move throwable upgrades calculation back into try/catch
lili2311 a0b4bf7
feat: fix sequentially support for Pipenv
lili2311 b587e46
chore: rename --sequential-update to --sequential
lili2311 a5a618c
chore: rename ensureHasUpdates & update comments
lili2311 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 17 additions & 0 deletions
17
...k-fix/src/plugins/python/handlers/pipenv-pipfile/update-dependencies/generate-upgrades.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import { EntityToFix } from '../../../../../types'; | ||
import { standardizePackageName } from '../../../standardize-package-name'; | ||
import { validateRequiredData } from '../../validate-required-data'; | ||
|
||
export function generateUpgrades(entity: EntityToFix): { upgrades: string[] } { | ||
const { remediation } = validateRequiredData(entity); | ||
const { pin: pins } = remediation; | ||
|
||
const upgrades: string[] = []; | ||
for (const pkgAtVersion of Object.keys(pins)) { | ||
const pin = pins[pkgAtVersion]; | ||
const newVersion = pin.upgradeTo.split('@')[1]; | ||
const [pkgName] = pkgAtVersion.split('@'); | ||
upgrades.push(`${standardizePackageName(pkgName)}==${newVersion}`); | ||
} | ||
return { upgrades }; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
70 changes: 70 additions & 0 deletions
70
...ages/snyk-fix/src/plugins/python/handlers/poetry/update-dependencies/generate-upgrades.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
import * as pathLib from 'path'; | ||
import * as toml from 'toml'; | ||
|
||
import * as debugLib from 'debug'; | ||
|
||
import { EntityToFix } from '../../../../../types'; | ||
|
||
import { validateRequiredData } from '../../validate-required-data'; | ||
import { standardizePackageName } from '../../../standardize-package-name'; | ||
|
||
const debug = debugLib('snyk-fix:python:Poetry'); | ||
|
||
interface PyProjectToml { | ||
tool: { | ||
poetry: { | ||
name: string; | ||
version: string; | ||
description: string; | ||
authors: string[]; | ||
dependencies?: object; | ||
'dev-dependencies'?: object; | ||
}; | ||
}; | ||
} | ||
|
||
export async function generateUpgrades( | ||
entity: EntityToFix, | ||
): Promise<{ upgrades: string[]; devUpgrades: string[] }> { | ||
const { remediation, targetFile } = validateRequiredData(entity); | ||
const pins = remediation.pin; | ||
|
||
const targetFilePath = pathLib.resolve(entity.workspace.path, targetFile); | ||
const { dir } = pathLib.parse(targetFilePath); | ||
const pyProjectTomlRaw = await entity.workspace.readFile( | ||
pathLib.resolve(dir, 'pyproject.toml'), | ||
); | ||
const pyProjectToml: PyProjectToml = toml.parse(pyProjectTomlRaw); | ||
|
||
const prodTopLevelDeps = Object.keys( | ||
pyProjectToml.tool.poetry.dependencies ?? {}, | ||
).map((dep) => standardizePackageName(dep)); | ||
const devTopLevelDeps = Object.keys( | ||
pyProjectToml.tool.poetry['dev-dependencies'] ?? {}, | ||
).map((dep) => standardizePackageName(dep)); | ||
|
||
const upgrades: string[] = []; | ||
const devUpgrades: string[] = []; | ||
for (const pkgAtVersion of Object.keys(pins)) { | ||
const pin = pins[pkgAtVersion]; | ||
const newVersion = pin.upgradeTo.split('@')[1]; | ||
const [pkgName] = pkgAtVersion.split('@'); | ||
|
||
const upgrade = `${standardizePackageName(pkgName)}==${newVersion}`; | ||
|
||
if (pin.isTransitive || prodTopLevelDeps.includes(pkgName)) { | ||
// transitive and it could have come from a dev or prod dep | ||
// since we can't tell right now let be pinned into production deps | ||
upgrades.push(upgrade); | ||
} else if (prodTopLevelDeps.includes(pkgName)) { | ||
upgrades.push(upgrade); | ||
} else if (entity.options.dev && devTopLevelDeps.includes(pkgName)) { | ||
devUpgrades.push(upgrade); | ||
} else { | ||
debug( | ||
`Could not determine what type of upgrade ${upgrade} is. When choosing between: transitive upgrade, production or dev direct upgrade. `, | ||
); | ||
} | ||
} | ||
return { upgrades, devUpgrades }; | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
move back into try/catch to not prevent further fixes & to let the spinner finish