refactor: use parentOf relations instead of using spec.children

Signed-off-by: Marley <55280588+marleypowell@users.noreply.github.com>
This commit is contained in:
Marley
2024-04-09 09:16:52 +00:00
parent 99870667c7
commit 7703c53089
@@ -28,6 +28,7 @@ import {
isGroupEntity,
isUserEntity,
RELATION_HAS_MEMBER,
RELATION_PARENT_OF,
stringifyEntityRef,
} from '@backstage/catalog-model';
import { NotificationProcessor } from '@backstage/plugin-notifications-node';
@@ -102,7 +103,7 @@ export async function createRouter(
const entities = await catalogClient.getEntitiesByRefs(
{
entityRefs: refs,
fields: ['kind', 'metadata.name', 'metadata.namespace', 'relations', 'spec.children'],
fields: ['kind', 'metadata.name', 'metadata.namespace', 'relations'],
},
{ token },
);
@@ -120,10 +121,23 @@ export async function createRouter(
relation.type === RELATION_HAS_MEMBER && relation.targetRef,
)
.map(r => r.targetRef);
const childGroupRefs = entity.relations
.filter(
relation =>
relation.type === RELATION_PARENT_OF && relation.targetRef,
)
.map(r => r.targetRef);
const childGroups = await catalogClient.getEntitiesByRefs(
{
entityRefs: entity.spec.children,
fields: ['kind', 'metadata.name', 'metadata.namespace', 'relations', 'spec.children'],
entityRefs: childGroupRefs,
fields: [
'kind',
'metadata.name',
'metadata.namespace',
'relations',
],
},
{ token },
);