Skip to content

Commit

Permalink
Merge pull request #5101 from opsmill/pog-update-artifact-targets-IFC…
Browse files Browse the repository at this point in the history
…-963

Support updating artifact definition targets
  • Loading branch information
ogenstad authored Dec 3, 2024
2 parents 80e63e6 + 1c61013 commit 7603f76
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 2 deletions.
8 changes: 7 additions & 1 deletion backend/infrahub/git/integrator.py
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,9 @@ async def import_artifact_definitions(

artifact_defs_in_graph = {
artdef.name.value: artdef
for artdef in await self.sdk.filters(kind=CoreArtifactDefinition, branch=branch_name)
for artdef in await self.sdk.filters(
kind=CoreArtifactDefinition, branch=branch_name, prefetch_relationships=True, populate_store=True
)
}

local_artifact_defs: dict[str, InfrahubRepositoryArtifactDefinitionConfig] = {}
Expand Down Expand Up @@ -380,6 +382,7 @@ async def compare_artifact_definition(
existing_artifact_definition.artifact_name.value != local_artifact_definition.artifact_name
or existing_artifact_definition.parameters.value != local_artifact_definition.parameters
or existing_artifact_definition.content_type.value != local_artifact_definition.content_type
or existing_artifact_definition.targets.peer.name.value != local_artifact_definition.targets
):
return False

Expand All @@ -399,6 +402,9 @@ async def update_artifact_definition(
if existing_artifact_definition.content_type.value != local_artifact_definition.content_type:
existing_artifact_definition.content_type.value = local_artifact_definition.content_type

if existing_artifact_definition.targets.peer.name.value != local_artifact_definition.targets:
existing_artifact_definition.targets = local_artifact_definition.targets

await existing_artifact_definition.save()

async def get_repository_config(self, branch_name: str, commit: str) -> Optional[InfrahubRepositoryConfig]:
Expand Down
4 changes: 3 additions & 1 deletion backend/infrahub/git/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,7 @@ async def generate_request_artifact_definition(model: RequestArtifactDefinitionG
await artifact_definition.targets.fetch()
group = artifact_definition.targets.peer
await group.members.fetch()
current_members = [member.id for member in group.members.peers]

existing_artifacts = await service.client.filters(
kind=InfrahubKind.ARTIFACT,
Expand All @@ -183,7 +184,8 @@ async def generate_request_artifact_definition(model: RequestArtifactDefinitionG
)
artifacts_by_member = {}
for artifact in existing_artifacts:
artifacts_by_member[artifact.object.peer.id] = artifact.id
if artifact.object.id in current_members:
artifacts_by_member[artifact.object.peer.id] = artifact.id

await artifact_definition.transformation.fetch()
transformation_repository = artifact_definition.transformation.peer.repository
Expand Down
1 change: 1 addition & 0 deletions changelog/5060.fixed.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix artifact definition targets when changed in repo so that it's reflected in the database

0 comments on commit 7603f76

Please sign in to comment.