|
11 | 11 | from ..v2.codetf import AIMetadata as AIMetadatav2 |
12 | 12 | from ..v2.codetf import ChangeSet as v2ChangeSet |
13 | 13 | from ..v2.codetf import CodeTF as CodeTFv2 |
| 14 | +from ..v2.codetf import Finding as v2Finding |
14 | 15 | from ..v2.codetf import Result |
15 | 16 | from ..v2.codetf import Run as Runv2 |
16 | 17 |
|
@@ -151,31 +152,55 @@ def from_v2_aimetadata(ai_metadata: AIMetadatav2) -> AIMetadata: |
151 | 152 | ) |
152 | 153 |
|
153 | 154 |
|
154 | | -def from_v2_result_per_finding(result: Result) -> FixResult | None: |
| 155 | +def from_v2_result_per_finding( |
| 156 | + result: Result, |
| 157 | + strategy: Strategy | None = None, |
| 158 | + ai_metadata: AIMetadata | None = None, |
| 159 | + provisional: bool | None = None, |
| 160 | +) -> FixResult | None: |
155 | 161 | """ |
156 | 162 | This transformation assumes that the v2 result will only contain a single fixedFinding for all changesets. |
157 | 163 | """ |
| 164 | + |
| 165 | + changeset: v2ChangeSet | None = None |
| 166 | + finding: v2Finding | None = None |
158 | 167 | # Find the changeset with a fixedFinding |
159 | | - try: |
160 | | - changeset: v2ChangeSet = next(cs for cs in result.changeset if cs.fixedFindings) |
161 | | - except StopIteration: |
162 | | - logger.debug("Either no changesets or no fixedFinding in the given Result") |
| 168 | + for cs in result.changeset: |
| 169 | + if cs.fixedFindings: |
| 170 | + changeset = cs |
| 171 | + finding = cs.fixedFindings[0] |
| 172 | + break |
| 173 | + else: |
| 174 | + # check each individual change |
| 175 | + for change in cs.changes: |
| 176 | + if change.fixedFindings: |
| 177 | + changeset = cs |
| 178 | + finding = change.fixedFindings[0] |
| 179 | + break |
| 180 | + if changeset is None or finding is None: |
| 181 | + logger.debug("Either no changesets or fixed finding in the result") |
163 | 182 | return None |
164 | 183 |
|
165 | | - assert changeset.fixedFindings |
166 | | - finding = changeset.fixedFindings[0] |
167 | | - |
168 | 184 | v3changesets = [ |
169 | 185 | ChangeSet( |
170 | 186 | path=cs.path, diff=cs.diff, changes=[c.to_common() for c in cs.changes] |
171 | 187 | ) |
172 | 188 | for cs in result.changeset |
173 | 189 | ] |
174 | 190 |
|
| 191 | + # Generate the GenerationMetadata from the changeset if not passed as a parameter |
| 192 | + fix_result_strategy = strategy or ( |
| 193 | + Strategy.ai if changeset.ai else Strategy.deterministic |
| 194 | + ) |
| 195 | + fix_result_ai_metadata = ai_metadata or ( |
| 196 | + from_v2_aimetadata(changeset.ai) if changeset.ai else None |
| 197 | + ) |
| 198 | + fix_result_provisional = provisional or changeset.provisional or False |
| 199 | + |
175 | 200 | generation_metadata = GenerationMetadata( |
176 | | - strategy=Strategy.ai if changeset.ai else Strategy.deterministic, |
177 | | - ai=from_v2_aimetadata(changeset.ai) if changeset.ai else None, |
178 | | - provisional=False, |
| 201 | + strategy=fix_result_strategy, |
| 202 | + ai=fix_result_ai_metadata, |
| 203 | + provisional=fix_result_provisional, |
179 | 204 | ) |
180 | 205 |
|
181 | 206 | fix_metadata = FixMetadata( |
|
0 commit comments