Skip to content

Commit

Permalink
Merge pull request #347 from alodela/al/entity-ref-fix
Browse files Browse the repository at this point in the history
fix(yaml-actions): Update entity by metadata name
  • Loading branch information
taras authored Sep 18, 2023
2 parents 48fd3ae + c929ea9 commit f822b82
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 5 deletions.
5 changes: 5 additions & 0 deletions .changeset/tough-keys-reflect.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@frontside/scaffolder-yaml-actions': patch
---

Support entity updates by metadata name
28 changes: 26 additions & 2 deletions plugins/scaffolder-yaml-actions/src/operations/append.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -25,4 +25,28 @@ describe('append', () => {
- production
`)
});
});
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
`)
});
});
4 changes: 2 additions & 2 deletions plugins/scaffolder-yaml-actions/src/operations/append.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -43,4 +43,4 @@ export function append({
}

return documents.map(document => document.toString()).join('');
}
}
23 changes: 23 additions & 0 deletions plugins/scaffolder-yaml-actions/src/operations/set.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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!!!
`)
});
});

2 changes: 1 addition & 1 deletion plugins/scaffolder-yaml-actions/src/operations/set.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit f822b82

Please sign in to comment.