-
Notifications
You must be signed in to change notification settings - Fork 10
Added v2 to v3 result transformation that includes package changes #1079
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
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -5,8 +5,11 @@ | |||||
|
|
||||||
| from pydantic import BaseModel, model_validator | ||||||
|
|
||||||
| from codemodder.logging import logger | ||||||
|
|
||||||
| from ..common import Change, CodeTFWriter, Finding, FixQuality | ||||||
| from ..v2.codetf import AIMetadata as AIMetadatav2 | ||||||
| from ..v2.codetf import ChangeSet as v2ChangeSet | ||||||
| from ..v2.codetf import CodeTF as CodeTFv2 | ||||||
| from ..v2.codetf import Result | ||||||
| from ..v2.codetf import Run as Runv2 | ||||||
|
|
@@ -148,6 +151,48 @@ def from_v2_aimetadata(ai_metadata: AIMetadatav2) -> AIMetadata: | |||||
| ) | ||||||
|
|
||||||
|
|
||||||
| def from_v2_result_per_finding(result: Result) -> FixResult | None: | ||||||
| """ | ||||||
| This transformation assumes that the v2 result will only contain a single fixedFinding for all changesets. | ||||||
| """ | ||||||
| # Find the changeset with a fixedFinding | ||||||
| try: | ||||||
| changeset: v2ChangeSet = next(cs for cs in result.changeset if cs.fixedFindings) | ||||||
| except StopIteration: | ||||||
| logger.debug("Either no changesets or no fixedFinding in the given Result") | ||||||
| return None | ||||||
|
|
||||||
| assert changeset.fixedFindings | ||||||
| finding = changeset.fixedFindings[0] | ||||||
|
|
||||||
| v3changesets = [ | ||||||
| ChangeSet( | ||||||
| path=cs.path, diff=cs.diff, changes=[c.to_common() for c in cs.changes] | ||||||
| ) | ||||||
| for cs in result.changeset | ||||||
| ] | ||||||
|
|
||||||
| generation_metadata = GenerationMetadata( | ||||||
| strategy=Strategy.ai if changeset.ai else Strategy.deterministic, | ||||||
| ai=from_v2_aimetadata(changeset.ai) if changeset.ai else None, | ||||||
| provisional=False, | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. will this function always be called from non-provisional contexts?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No clue, not sure why this flag exists in the first place.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. provisional=True is "magic"... maybe we no longer make this distinction ?
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It should be derived from the v2 changeset the same way as these other metadata fields.
Suggested change
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is there any chance that for our purposes it makes more sense to pass in these metadata fields as parameters to this new function? For the use case I'm thinking of, I'd argue that the answer is yes. |
||||||
| ) | ||||||
|
|
||||||
| fix_metadata = FixMetadata( | ||||||
| id=result.codemod, | ||||||
| summary=result.summary, | ||||||
| description=result.description, | ||||||
| generation=generation_metadata, | ||||||
| ) | ||||||
|
|
||||||
| return FixResult( | ||||||
| finding=Finding(**finding.model_dump()), | ||||||
| fixStatus=FixStatus(status=FixStatusType.fixed), | ||||||
| changeSets=v3changesets, | ||||||
| fixMetadata=fix_metadata, | ||||||
| ) | ||||||
|
|
||||||
|
|
||||||
| def from_v2_result(result: Result) -> list[FixResult]: | ||||||
| fix_results: list[FixResult] = [] | ||||||
| # generate fixed | ||||||
|
|
||||||
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.
Fixed findings can belong to individual
Changeentries of a change set as well, so you need to check there too, both here and below.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.
Those are usually replicated. That is, the changeset
fixedFindingsshould always include the ones contained in the changes.I'll make it check each individual change in any case.