22
33from typing import TYPE_CHECKING
44
5- from infrahub .core .constants import RepositoryInternalStatus
5+ from infrahub .core .constants import InfrahubKind , RepositoryInternalStatus
66from infrahub .core .diff .model .path import BranchTrackingId
77from infrahub .core .manager import NodeManager
88from infrahub .core .models import SchemaUpdateValidationResult
9- from infrahub .core .protocols import CoreRepository
9+ from infrahub .core .protocols import CoreReadOnlyRepository , CoreRepository
1010from infrahub .core .registry import registry
1111from infrahub .core .timestamp import Timestamp
1212from infrahub .exceptions import MergeFailedError , ValidationError
@@ -223,6 +223,32 @@ async def rollback(self) -> None:
223223 await self .diff_merger .rollback (at = self ._merge_at )
224224
225225 async def merge_repositories (self ) -> None :
226+ await self .merge_core_read_only_repositories ()
227+ await self .merge_core_repositories ()
228+
229+ async def merge_core_read_only_repositories (self ) -> None :
230+ repos_in_main_list = await NodeManager .query (schema = CoreReadOnlyRepository , db = self .db )
231+ repos_in_main = {repo .id : repo for repo in repos_in_main_list }
232+
233+ repos_in_branch_list = await NodeManager .query (
234+ schema = CoreReadOnlyRepository , db = self .db , branch = self .source_branch
235+ )
236+ for repo in repos_in_branch_list :
237+ if repo .id not in repos_in_main :
238+ continue
239+
240+ model = GitRepositoryMerge (
241+ repository_id = repo .id ,
242+ repository_name = repo .name .value ,
243+ source_branch = self .source_branch .name ,
244+ destination_branch = self .destination_branch .name ,
245+ destination_branch_id = str (self .destination_branch .get_uuid ()),
246+ internal_status = repo .internal_status .value ,
247+ repository_kind = InfrahubKind .READONLYREPOSITORY ,
248+ )
249+ await self .workflow .submit_workflow (workflow = GIT_REPOSITORIES_MERGE , parameters = {"model" : model })
250+
251+ async def merge_core_repositories (self ) -> None :
226252 # Collect all Repositories in Main because we'll need the commit in Main for each one.
227253 repos_in_main_list = await NodeManager .query (schema = CoreRepository , db = self .db )
228254 repos_in_main = {repo .id : repo for repo in repos_in_main_list }
@@ -245,5 +271,6 @@ async def merge_repositories(self) -> None:
245271 destination_branch = self .destination_branch .name ,
246272 destination_branch_id = str (self .destination_branch .get_uuid ()),
247273 default_branch = repo .default_branch .value ,
274+ repository_kind = InfrahubKind .REPOSITORY ,
248275 )
249276 await self .workflow .submit_workflow (workflow = GIT_REPOSITORIES_MERGE , parameters = {"model" : model })
0 commit comments