-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Convert BranchDelete task and event to Prefect
- Loading branch information
Showing
24 changed files
with
149 additions
and
272 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,6 +6,7 @@ on: | |
push: | ||
branches: | ||
- develop | ||
- develop-* | ||
- stable | ||
- release-* | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
from pydantic import Field | ||
|
||
from infrahub.message_bus import InfrahubMessage | ||
from infrahub.message_bus.messages.event_branch_delete import EventBranchDelete | ||
from infrahub.message_bus.messages.refresh_registry_branches import RefreshRegistryBranches | ||
|
||
from .models import InfrahubBranchEvent | ||
|
||
|
||
class BranchDeleteEvent(InfrahubBranchEvent): | ||
"""Event generated when a branch has been deleted""" | ||
|
||
branch_id: str = Field(..., description="The ID of the mutated node") | ||
sync_with_git: bool = Field(..., description="Indicates if the branch was extended to Git") | ||
|
||
def get_name(self) -> str: | ||
return f"{self.get_event_namespace()}.branch.deleted" | ||
|
||
def get_resource(self) -> dict[str, str]: | ||
return { | ||
"prefect.resource.id": f"infrahub.branch.{self.branch}", | ||
"infrahub.branch.id": self.branch_id, | ||
} | ||
|
||
def get_messages(self) -> list[InfrahubMessage]: | ||
events = [ | ||
EventBranchDelete( | ||
branch=self.branch, | ||
branch_id=self.branch_id, | ||
sync_with_git=self.sync_with_git, | ||
meta=self.get_message_meta(), | ||
), | ||
RefreshRegistryBranches(), | ||
] | ||
return events |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 0 additions & 9 deletions
9
backend/infrahub/message_bus/messages/request_proposed_change_cancel.py
This file was deleted.
Oops, something went wrong.
9 changes: 0 additions & 9 deletions
9
backend/infrahub/message_bus/messages/trigger_proposed_change_cancel.py
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
from . import generator_definition, proposed_change, webhook | ||
from . import generator_definition, webhook | ||
|
||
__all__ = ["generator_definition", "proposed_change", "webhook"] | ||
__all__ = ["generator_definition", "webhook"] |
27 changes: 0 additions & 27 deletions
27
backend/infrahub/message_bus/operations/trigger/proposed_change.py
This file was deleted.
Oops, something went wrong.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
from __future__ import annotations | ||
|
||
from infrahub_sdk.protocols import CoreProposedChange | ||
from prefect import flow, task | ||
from prefect.logging import get_run_logger | ||
|
||
from infrahub.core.constants import ProposedChangeState | ||
from infrahub.services import ( | ||
services, | ||
) | ||
|
||
|
||
@flow(name="proposed-changes-cancel-branch", description="Cancel all Proposed change associated with a branch.") | ||
async def cancel_proposed_changes_branch(branch_name: str) -> None: | ||
service = services.service | ||
proposed_changed_opened = await service.client.filters( | ||
kind=CoreProposedChange, | ||
include=["id", "source_branch"], | ||
state__value=ProposedChangeState.OPEN.value, | ||
source_branch__value=branch_name, | ||
) | ||
proposed_changed_closed = await service.client.filters( | ||
kind=CoreProposedChange, | ||
include=["id", "source_branch"], | ||
state__value=ProposedChangeState.CLOSED.value, | ||
source_branch__value=branch_name, | ||
) | ||
|
||
for proposed_change in proposed_changed_opened + proposed_changed_closed: | ||
await cancel_proposed_change(proposed_change=proposed_change) | ||
|
||
|
||
@task(description="Cancel a propose change") | ||
async def cancel_proposed_change(proposed_change: CoreProposedChange) -> None: | ||
service = services.service | ||
log = get_run_logger() | ||
|
||
log.info("Canceling proposed change as the source branch was deleted") | ||
proposed_change = await service.client.get(kind=CoreProposedChange, id=proposed_change.id) | ||
proposed_change.state.value = ProposedChangeState.CANCELED.value | ||
await proposed_change.save() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.