diff --git a/.changeset/tough-keys-reflect.md b/.changeset/tough-keys-reflect.md new file mode 100644 index 0000000000..ef88b3d849 --- /dev/null +++ b/.changeset/tough-keys-reflect.md @@ -0,0 +1,5 @@ +--- +'@frontside/scaffolder-yaml-actions': patch +--- + +Support entity updates by metadata name diff --git a/plugins/scaffolder-yaml-actions/src/operations/append.test.ts b/plugins/scaffolder-yaml-actions/src/operations/append.test.ts index 359f56e1b4..a60023607b 100644 --- a/plugins/scaffolder-yaml-actions/src/operations/append.test.ts +++ b/plugins/scaffolder-yaml-actions/src/operations/append.test.ts @@ -15,7 +15,7 @@ describe('append', () => { it("creates collection when it doesn't exist", () => { expect(append({ content: `metadata: - foo: + foo: `, path: 'metadata.tags', value: 'production' @@ -25,4 +25,28 @@ describe('append', () => { - production `) }); -}); \ No newline at end of file + it('adds to the resource entity', () => { + expect(append({ + content: `metadata: + name: entity-a +kind: component +--- +metadata: + name: entity-b +kind: resource + `, + path: 'metadata.tags', + value: 'production', + entityRef: 'resource:default/entity-b' + })).toEqual(`metadata: + name: entity-a +kind: component +--- +metadata: + name: entity-b + tags: + - production +kind: resource +`) + }); +}); diff --git a/plugins/scaffolder-yaml-actions/src/operations/append.ts b/plugins/scaffolder-yaml-actions/src/operations/append.ts index 2bd3306ae9..9cdcebbc4a 100644 --- a/plugins/scaffolder-yaml-actions/src/operations/append.ts +++ b/plugins/scaffolder-yaml-actions/src/operations/append.ts @@ -19,7 +19,7 @@ export function append({ const maybeEntity = document.contents.toJSON(); if (typeof maybeEntity.kind === 'string' && - typeof maybeEntity.name === 'string' && + (typeof maybeEntity.name === 'string' || typeof maybeEntity.metadata?.name === 'string') && entityRef && stringifyEntityRef(maybeEntity) !== entityRef) { continue; @@ -43,4 +43,4 @@ export function append({ } return documents.map(document => document.toString()).join(''); -} \ No newline at end of file +} diff --git a/plugins/scaffolder-yaml-actions/src/operations/set.test.ts b/plugins/scaffolder-yaml-actions/src/operations/set.test.ts index 024b6ecfd5..f88364e158 100644 --- a/plugins/scaffolder-yaml-actions/src/operations/set.test.ts +++ b/plugins/scaffolder-yaml-actions/src/operations/set.test.ts @@ -22,5 +22,28 @@ describe('set', () => { value: 'world!!!' })).toBe("hello: world!!!\n") }); + it('allows to set value to resource entity', () => { + expect(set({ + content: `metadata: + name: entity-a +kind: component +--- +metadata: + name: entity-b +kind: resource +`, + path: 'hello', + value: 'world!!!', + entityRef: 'resource:default/entity-b' + })).toBe(`metadata: + name: entity-a +kind: component +--- +metadata: + name: entity-b +kind: resource +hello: world!!! +`) + }); }); diff --git a/plugins/scaffolder-yaml-actions/src/operations/set.ts b/plugins/scaffolder-yaml-actions/src/operations/set.ts index a903eb83df..ff08b8ad15 100644 --- a/plugins/scaffolder-yaml-actions/src/operations/set.ts +++ b/plugins/scaffolder-yaml-actions/src/operations/set.ts @@ -21,7 +21,7 @@ export function set({ const maybeEntity = document.contents.toJSON(); if (typeof maybeEntity.kind === 'string' && - typeof maybeEntity.name === 'string' && + (typeof maybeEntity.name === 'string' || typeof maybeEntity.metadata?.name === 'string') && entityRef && stringifyEntityRef(maybeEntity) !== entityRef) { continue;