-
Notifications
You must be signed in to change notification settings - Fork 13
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Convert BranchDelete task and event to Prefect #4778
Open
dgarros
wants to merge
1
commit into
develop-1.1
Choose a base branch
from
dga-20241030-events
base: develop-1.1
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+149
−272
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
NotImplentedError()