Skip to content

Commit 2ce6e23

Browse files
authored
Merge pull request #5776 from opsmill/pog-ancestor-events-IFC-1252
Add list of ancestor events
2 parents 14b4b5d + edf134f commit 2ce6e23

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

backend/infrahub/events/models.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,11 @@ class EventNode(BaseModel):
2020
kind: str
2121

2222

23+
class ParentEvent(BaseModel):
24+
id: str
25+
name: str
26+
27+
2328
class EventMeta(BaseModel):
2429
branch: Branch | None = Field(default=None)
2530
request_id: str = ""
@@ -39,6 +44,7 @@ class EventMeta(BaseModel):
3944
)
4045

4146
parent: UUID | None = Field(default=None, description="The UUID of the parent event if applicable")
47+
ancestors: list[ParentEvent] = Field(default_factory=list, description="Any event used to trigger this event")
4248

4349
def get_branch_id(self) -> str:
4450
if self.context.branch.id:
@@ -83,6 +89,15 @@ def get_related(self) -> list[dict[str, str]]:
8389
}
8490
)
8591

92+
for ancestor in self.ancestors:
93+
related.append(
94+
{
95+
"prefect.resource.id": ancestor.id,
96+
"prefect.resource.role": "infrahub.ancestor_event",
97+
"infrahub.ancestor_event.name": ancestor.name,
98+
}
99+
)
100+
86101
return related
87102

88103
@classmethod
@@ -109,6 +124,7 @@ def from_parent(cls, parent: InfrahubEvent) -> EventMeta:
109124
account_id=parent.meta.account_id,
110125
level=parent.meta.level + 1,
111126
context=parent.meta.context,
127+
ancestors=[ParentEvent(id=parent.get_id(), name=parent.get_name())] + parent.meta.ancestors,
112128
)
113129

114130

0 commit comments

Comments
 (0)