-
Notifications
You must be signed in to change notification settings - Fork 28
Support converting repository type #6469
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
Draft
LucasG0
wants to merge
2
commits into
develop
Choose a base branch
from
lgu-convert-repos
base: develop
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.
+1,238
−250
Draft
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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 hidden or 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 hidden or 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 hidden or 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 hidden or 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,7 @@ | ||
from infrahub.utils import InfrahubStringEnum | ||
|
||
|
||
class BranchStatus(InfrahubStringEnum): | ||
ACTIVE = "ACTIVE" | ||
NEED_REBASE = "NEED_REBASE" | ||
CLOSED = "CLOSED" |
This file contains hidden or 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 hidden or 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,2 @@ | ||
def raise_needs_rebase_error(branch_name: str) -> None: | ||
raise ValueError(f"Branch {branch_name} should be rebased before performing other operation on it") |
This file contains hidden or 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
46 changes: 46 additions & 0 deletions
46
backend/infrahub/core/convert_object_type/repository_conversion.py
This file contains hidden or 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,46 @@ | ||
from infrahub import lock | ||
from infrahub.core.branch import Branch | ||
from infrahub.core.convert_object_type.object_conversion import InputForDestField, convert_object_type | ||
from infrahub.core.manager import NodeManager | ||
from infrahub.core.node import Node | ||
from infrahub.core.repositories.create_repository import RepositoryFinalizer | ||
from infrahub.core.schema import NodeSchema | ||
from infrahub.database import InfrahubDatabase | ||
|
||
|
||
async def convert_repository_type( | ||
node: Node, | ||
target_schema: NodeSchema, | ||
mapping: dict[str, InputForDestField], | ||
branch: Branch, | ||
db: InfrahubDatabase, | ||
repository_post_creator: RepositoryFinalizer, | ||
) -> Node: | ||
"""Delete the node and return the new created one. If creation fails, the node is not deleted, and raise an error. | ||
An extra check is performed on input node peers relationships to make sure they are still valid.""" | ||
|
||
repo_name = node.name.value # type: ignore [attr-defined] | ||
async with lock.registry.get(name=repo_name, namespace="repository"): | ||
node_created = await convert_object_type( | ||
node=node, | ||
target_schema=target_schema, | ||
mapping=mapping, | ||
branch=branch, | ||
db=db, | ||
) | ||
|
||
# We can't apply post creation steps within `convert_object_type` transaction as a sdk call tries to fetch the node | ||
# created within the transaction from a different process, therefore that would not run within this transaction | ||
# so the node ends up being not found | ||
await repository_post_creator.post_create( | ||
branch=branch, | ||
obj=node_created, # type: ignore | ||
db=db, | ||
) | ||
|
||
# Delete the RepositoryGroup associated with the old repository, as a new one was created for the new repository. | ||
repository_groups = (await node.groups_objects.get_peers(db=db)).values() # type: ignore [attr-defined] | ||
for repository_group in repository_groups: | ||
await NodeManager.delete(db=db, branch=branch, nodes=[repository_group], cascade_delete=False) | ||
|
||
return node_created |
This file contains hidden or 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 hidden or 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 hidden or 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.
Uh oh!
There was an error while loading. Please reload this page.