Skip to content

Commit dddd72a

Browse files
authored
Add proposed change event when multiple approvals are revoked (#7033)
1 parent a012c36 commit dddd72a

File tree

6 files changed

+65
-1
lines changed

6 files changed

+65
-1
lines changed

backend/infrahub/core/constants/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ class EventType(InfrahubStringEnum):
6666
PROPOSED_CHANGE_APPROVED = f"{EVENT_NAMESPACE}.proposed_change.approved"
6767
PROPOSED_CHANGE_REJECTED = f"{EVENT_NAMESPACE}.proposed_change.rejected"
6868
PROPOSED_CHANGE_APPROVAL_REVOKED = f"{EVENT_NAMESPACE}.proposed_change.approval_revoked"
69+
PROPOSED_CHANGE_APPROVALS_REVOKED = f"{EVENT_NAMESPACE}.proposed_change.approvals_revoked"
6970
PROPOSED_CHANGE_REJECTION_REVOKED = f"{EVENT_NAMESPACE}.proposed_change.rejection_revoked"
7071
PROPOSED_CHANGE_THREAD_CREATED = f"{EVENT_NAMESPACE}.proposed_change_thread.created"
7172
PROPOSED_CHANGE_THREAD_UPDATED = f"{EVENT_NAMESPACE}.proposed_change_thread.updated"

backend/infrahub/events/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
from .node_action import NodeCreatedEvent, NodeDeletedEvent, NodeUpdatedEvent
66
from .proposed_change_action import (
77
ProposedChangeApprovalRevokedEvent,
8+
ProposedChangeApprovalsRevokedEvent,
89
ProposedChangeApprovedEvent,
910
ProposedChangeMergedEvent,
1011
ProposedChangeRejectedEvent,
@@ -32,6 +33,7 @@
3233
"NodeDeletedEvent",
3334
"NodeUpdatedEvent",
3435
"ProposedChangeApprovalRevokedEvent",
36+
"ProposedChangeApprovalsRevokedEvent",
3537
"ProposedChangeApprovedEvent",
3638
"ProposedChangeMergedEvent",
3739
"ProposedChangeRejectedEvent",

backend/infrahub/events/proposed_change_action.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,28 @@ class ProposedChangeRejectionRevokedEvent(ProposedChangeReviewRevokedEvent):
150150
event_name: ClassVar[str] = f"{EVENT_NAMESPACE}.proposed_change.rejection_revoked"
151151

152152

153+
class ProposedChangeApprovalsRevokedEvent(ProposedChangeEvent):
154+
reviewer_accounts: dict[str, str] = Field(
155+
default_factory=dict, description="ID to name map of accounts whose approval was revoked"
156+
)
157+
158+
event_name: ClassVar[str] = f"{EVENT_NAMESPACE}.proposed_change.approvals_revoked"
159+
160+
def get_related(self) -> list[dict[str, str]]:
161+
related = super().get_related()
162+
for account_id, account_name in self.reviewer_accounts.items():
163+
related.append(
164+
{
165+
"prefect.resource.id": account_id,
166+
"prefect.resource.role": "infrahub.related.node",
167+
"infrahub.node.kind": InfrahubKind.GENERICACCOUNT,
168+
"infrahub.node.id": account_id,
169+
"infrahub.reviewer.account.name": account_name,
170+
}
171+
)
172+
return related
173+
174+
153175
class ProposedChangeThreadEvent(ProposedChangeEvent):
154176
thread_id: str = Field(..., description="The ID of the thread that was created or updated")
155177
thread_kind: str = Field(..., description="The name of the thread that was created or updated")

backend/infrahub/graphql/types/event.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,13 @@ class Meta:
136136
payload = Field(GenericScalar, required=True)
137137

138138

139+
class ProposedChangeApprovalsRevokedEvent(ObjectType):
140+
class Meta:
141+
interfaces = (EventNodeInterface,)
142+
143+
payload = Field(GenericScalar, required=True)
144+
145+
139146
class ProposedChangeReviewRequestedEvent(ObjectType):
140147
class Meta:
141148
interfaces = (EventNodeInterface,)
@@ -220,6 +227,7 @@ class Meta:
220227
events.ProposedChangeRejectedEvent.event_name: ProposedChangeReviewEvent,
221228
events.ProposedChangeRejectionRevokedEvent.event_name: ProposedChangeReviewRevokedEvent,
222229
events.ProposedChangeReviewRequestedEvent.event_name: ProposedChangeReviewRequestedEvent,
230+
events.ProposedChangeApprovalsRevokedEvent.event_name: ProposedChangeApprovalsRevokedEvent,
223231
events.ProposedChangeMergedEvent.event_name: ProposedChangeMergedEvent,
224232
events.ProposedChangeThreadCreatedEvent.event_name: ProposedChangeThreadEvent,
225233
events.ProposedChangeThreadUpdatedEvent.event_name: ProposedChangeThreadEvent,

backend/infrahub/task_manager/event.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,11 @@ def _return_event_specifics(self) -> dict[str, Any]:
242242
**self._return_proposed_change_event(),
243243
**self._return_proposed_change_reviewer_former_decision(),
244244
}
245-
case "infrahub.proposed_change.review_requested" | "infrahub.proposed_change.merged":
245+
case (
246+
"infrahub.proposed_change.approvals_revoked"
247+
| "infrahub.proposed_change.review_requested"
248+
| "infrahub.proposed_change.merged"
249+
):
246250
event_specifics = self._return_proposed_change_event()
247251

248252
return event_specifics

docs/docs/reference/infrahub-events.mdx

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -369,6 +369,33 @@ For more detailed explanations on how these events are used within Infrahub, see
369369
| **reviewer_former_decision** | The former decision made by the reviewer |
370370
<!-- vale on -->
371371
<!-- vale off -->
372+
### Proposed Change Approvals Revoked Event
373+
<!-- vale on -->
374+
375+
**Type**: infrahub.proposed_change.approvals_revoked
376+
<!-- vale off -->
377+
**Uses node_kind filter for webhooks**: `false`
378+
<!-- vale on -->
379+
380+
<!-- vale off -->
381+
| Key | Description |
382+
|-----|-------------|
383+
| **meta.branch** | The branch on which originate this event |
384+
| **meta.request_id** | N/A |
385+
| **meta.account_id** | The ID of the account triggering this event |
386+
| **meta.initiator_id** | The worker identity of the initial sender of this message |
387+
| **meta.context** | The context used when originating this event |
388+
| **meta.level** | N/A |
389+
| **meta.has_children** | Indicates if this event might potentially have child events under it. |
390+
| **meta.id** | UUID of the event |
391+
| **meta.parent** | The UUID of the parent event if applicable |
392+
| **meta.ancestors** | Any event used to trigger this event |
393+
| **proposed_change_id** | The ID of the proposed change |
394+
| **proposed_change_name** | The name of the proposed change |
395+
| **proposed_change_state** | The state of the proposed change |
396+
| **reviewer_accounts** | ID to name map of accounts whose approval was revoked |
397+
<!-- vale on -->
398+
<!-- vale off -->
372399
### Proposed Change Approved Event
373400
<!-- vale on -->
374401

0 commit comments

Comments
 (0)