Skip to content
This repository was archived by the owner on Jun 13, 2025. It is now read-only.

Commit 972108d

Browse files
committed
upate to same logic
1 parent 5d090c2 commit 972108d

File tree

1 file changed

+33
-7
lines changed

1 file changed

+33
-7
lines changed

graphql_api/types/commit/commit.py

Lines changed: 33 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@
2929
queryset_to_connection,
3030
queryset_to_connection_sync,
3131
)
32-
from graphql_api.types import coverage_totals
3332
from graphql_api.types.comparison.comparison import (
3433
MissingBaseCommit,
3534
MissingHeadReport,
@@ -271,13 +270,40 @@ def resolve_commit_bundle_analysis(commit, info):
271270

272271

273272
@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
278305

279-
if comparison and isinstance(comparison, ComparisonReport):
280-
return comparison.patch_totals
306+
return {**totals, "coverage": coverage}
281307

282308
return None
283309

0 commit comments

Comments
 (0)