Skip to content

Commit

Permalink
add diff conflict at the attribute level for value conflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
ajtmccarty committed Sep 3, 2024
1 parent 611b185 commit 184ec41
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
7 changes: 7 additions & 0 deletions backend/infrahub/graphql/queries/diff/tree.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

from infrahub.core import registry
from infrahub.core.constants import DiffAction, RelationshipCardinality
from infrahub.core.constants.database import DatabaseEdgeType
from infrahub.core.diff.model.path import NameTrackingId
from infrahub.core.diff.repository.repository import DiffRepository
from infrahub.core.query.diff import DiffCountChanges
Expand Down Expand Up @@ -75,6 +76,7 @@ class DiffAttribute(DiffSummaryCounts):
path_identifier = String(required=True)
properties = List(DiffProperty)
contains_conflict = Boolean(required=True)
conflict = Field(ConflictDetails, required=False)


class DiffSingleRelationship(DiffSummaryCounts):
Expand Down Expand Up @@ -207,13 +209,18 @@ def to_diff_attribute(
diff_properties = [
self.to_diff_property(enriched_property=e_prop, context=context) for e_prop in enriched_attribute.properties
]
conflict = None
for diff_prop in diff_properties:
if diff_prop.property_type == DatabaseEdgeType.HAS_VALUE.value and diff_prop.conflict:
conflict = diff_prop.conflict
return DiffAttribute(
name=enriched_attribute.name,
last_changed_at=enriched_attribute.changed_at.obj,
status=enriched_attribute.action,
path_identifier=enriched_attribute.path_identifier,
properties=diff_properties,
contains_conflict=enriched_attribute.contains_conflict,
conflict=conflict,
num_added=enriched_attribute.num_added,
num_updated=enriched_attribute.num_updated,
num_removed=enriched_attribute.num_removed,
Expand Down
24 changes: 24 additions & 0 deletions backend/tests/unit/graphql/test_diff_tree_query.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,18 @@
num_updated
num_conflicts
contains_conflict
conflict {
uuid
base_branch_action
base_branch_value
base_branch_changed_at
base_branch_label
diff_branch_action
diff_branch_value
diff_branch_changed_at
diff_branch_label
selected_branch
}
properties {
property_type
last_changed_at
Expand Down Expand Up @@ -353,6 +365,18 @@ async def test_diff_tree_one_attr_change(
"num_conflicts": 1,
"status": UPDATED_ACTION,
"contains_conflict": True,
"conflict": {
"uuid": enriched_conflict.uuid,
"base_branch_action": UPDATED_ACTION,
"base_branch_value": "#fedcba",
"base_branch_changed_at": enriched_conflict.base_branch_changed_at.to_string(with_z=False),
"base_branch_label": None,
"diff_branch_action": UPDATED_ACTION,
"diff_branch_value": "#abcdef",
"diff_branch_changed_at": enriched_conflict.diff_branch_changed_at.to_string(with_z=False),
"diff_branch_label": None,
"selected_branch": GraphQLConfictSelection.DIFF_BRANCH.name,
},
"properties": [
{
"property_type": "HAS_VALUE",
Expand Down

0 comments on commit 184ec41

Please sign in to comment.