|
29 | 29 | queryset_to_connection, |
30 | 30 | queryset_to_connection_sync, |
31 | 31 | ) |
32 | | -from graphql_api.types import coverage_totals |
33 | 32 | from graphql_api.types.comparison.comparison import ( |
34 | 33 | MissingBaseCommit, |
35 | 34 | MissingHeadReport, |
@@ -271,13 +270,40 @@ def resolve_commit_bundle_analysis(commit, info): |
271 | 270 |
|
272 | 271 |
|
273 | 272 | @commit_bindable.field("patchTotals") |
274 | | -async def resolve_patch_totals( |
275 | | - commit: Commit, info: GraphQLResolveInfo |
276 | | -) -> coverage_totals: # type: ignore |
277 | | - comparison = info.context.get("comparison", None) |
| 273 | +async def resolve_patch_totals(commit: Commit, info: GraphQLResolveInfo): |
| 274 | + if not commit.parent_commit_id: |
| 275 | + return None |
| 276 | + |
| 277 | + comparison_loader = ComparisonLoader.loader(info, commit.repository_id) |
| 278 | + commit_comparison = await comparison_loader.load( |
| 279 | + (commit.parent_commit_id, commit.commitid) |
| 280 | + ) |
| 281 | + |
| 282 | + # Validate the commit comparison but do not return an error |
| 283 | + validate_commit_comparison(commit_comparison=commit_comparison) |
| 284 | + |
| 285 | + if commit_comparison and commit_comparison.is_processed: |
| 286 | + current_owner = info.context["request"].current_owner |
| 287 | + parent_commit = await CommitLoader.loader(info, commit.repository_id).load( |
| 288 | + commit.parent_commit_id |
| 289 | + ) |
| 290 | + comparison = Comparison( |
| 291 | + user=current_owner, base_commit=parent_commit, head_commit=commit |
| 292 | + ) |
| 293 | + info.context["comparison"] = comparison |
| 294 | + |
| 295 | + if commit_comparison: |
| 296 | + totals = commit_comparison.patch_totals |
| 297 | + if not totals: |
| 298 | + return None |
| 299 | + |
| 300 | + coverage = totals["coverage"] |
| 301 | + if coverage is not None: |
| 302 | + # we always return `coverage` as a percentage but it's stored |
| 303 | + # in the database as 0 <= value <= 1 |
| 304 | + coverage *= 100 |
278 | 305 |
|
279 | | - if comparison and isinstance(comparison, ComparisonReport): |
280 | | - return comparison.patch_totals |
| 306 | + return {**totals, "coverage": coverage} |
281 | 307 |
|
282 | 308 | return None |
283 | 309 |
|
|
0 commit comments