Skip to content

Commit

Permalink
Merge branch 'main' into allow-jsonata-dry-run
Browse files Browse the repository at this point in the history
  • Loading branch information
Xantier authored Jul 21, 2023
2 parents 5bcc1b1 + 51d97fa commit 602ea41
Show file tree
Hide file tree
Showing 11 changed files with 158 additions and 82 deletions.
5 changes: 5 additions & 0 deletions .changeset/cool-coins-protect.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@roadiehq/backstage-plugin-argo-cd': patch
---

Fix for cases where argo application history source is Helm, which would cause revision metadata api to return 500
5 changes: 5 additions & 0 deletions .changeset/small-baboons-protect.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@roadiehq/backstage-plugin-argo-cd': patch
---

Use ErrorBoundary from @backstage/core-components
5 changes: 5 additions & 0 deletions .changeset/soft-forks-pull.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@roadiehq/scaffolder-backend-module-utils': patch
---

support object result in jsonata actions
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,13 @@ import {
useArgoCDAppData,
} from './useArgoCDAppData';
import {
ErrorBoundary,
InfoCard,
MissingAnnotationEmptyState,
Table,
TableColumn,
} from '@backstage/core-components';
import { configApiRef, useApi } from '@backstage/core-plugin-api';
import ErrorBoundary from './ErrorBoundary';
import { isArgocdAvailable } from '../conditions';
import { ArgoCDAppDetails, ArgoCDAppList } from '../types';
import { useAppDetails } from './useAppDetails';
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ export const useAppDetails = ({
const promises: Promise<void>[] | undefined =
appDetails.status?.history?.map(async (historyRecord: any) => {
const revisionID = historyRecord.revision;
if (historyRecord.source?.chart !== undefined) {
historyRecord.revision = { revisionID: revisionID };
return;
}
const revisionDetails = await api.getRevisionDetails({
url,
app,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ describe('roadiehq:utils:jsonata:json:transform', () => {
};
const action = createJsonJSONataTransformAction();

it('should output result of having applied the given transformation', async () => {
it('should output default string result of having applied the given transformation', async () => {
mock({
'fake-tmp-dir': {
'fake-file.json': '{ "hello": ["world"] }',
Expand All @@ -55,4 +55,47 @@ describe('roadiehq:utils:jsonata:json:transform', () => {
JSON.stringify({ hello: ['world', 'item2'] }),
);
});

it('should output string result of having applied the given transformation', async () => {
mock({
'fake-tmp-dir': {
'fake-file.json': '{ "hello": ["world"] }',
},
});
await action.handler({
...mockContext,
workspacePath: 'fake-tmp-dir',
input: {
path: 'fake-file.json',
expression: '$ ~> | $ | { "hello": [hello, "item2"] }|',
as: 'string',
},
});

expect(mockContext.output).toHaveBeenCalledWith(
'result',
JSON.stringify({ hello: ['world', 'item2'] }),
);
});

it('should output object result of having applied the given transformation', async () => {
mock({
'fake-tmp-dir': {
'fake-file.json': '{ "hello": ["world"] }',
},
});
await action.handler({
...mockContext,
workspacePath: 'fake-tmp-dir',
input: {
path: 'fake-file.json',
expression: '$ ~> | $ | { "hello": [hello, "item2"] }|',
as: 'object',
},
});

expect(mockContext.output).toHaveBeenCalledWith('result', {
hello: ['world', 'item2'],
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ export function createJsonJSONataTransformAction() {
expression: string;
replacer?: string[];
space?: string;
as?: 'string' | 'object';
}>({
id: 'roadiehq:utils:jsonata:json:transform',
description:
Expand All @@ -44,6 +45,13 @@ export function createJsonJSONataTransformAction() {
description: 'JSONata expression to perform on the input',
type: 'string',
},
as: {
title: 'Desired Result Type',
description:
'Permitted values are: "string" (default) and "object"',
type: 'string',
enum: ['string', 'object'],
},
replacer: {
title: 'Replacer',
description: 'Replacer array',
Expand All @@ -64,26 +72,30 @@ export function createJsonJSONataTransformAction() {
properties: {
result: {
title: 'Output result from JSONata',
type: 'object',
type: 'object | string',
},
},
},
},
async handler(ctx) {
let resultHandler: (rz: any) => any;

if (ctx.input.as === 'object') {
resultHandler = rz => rz;
} else {
resultHandler = rz =>
JSON.stringify(rz, ctx.input.replacer, ctx.input.space);
}
const sourceFilepath = resolveSafeChildPath(
ctx.workspacePath,
ctx.input.path,
);

const data = JSON.parse(fs.readFileSync(sourceFilepath).toString());
const expression = jsonata(ctx.input.expression);
const result = JSON.stringify(
expression.evaluate(data),
ctx.input.replacer,
ctx.input.space,
);
const result = expression.evaluate(data);

ctx.output('result', result);
ctx.output('result', resultHandler(result));
},
});
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ describe('roadiehq:utils:jsonata:yaml:transform', () => {
};
const action = createYamlJSONataTransformAction();

it('should output result of having applied the given transformation', async () => {
it('should output default string result of having applied the given transformation', async () => {
mock({
'fake-tmp-dir': {
'fake-file.yaml': 'hello: [world]',
Expand All @@ -57,6 +57,28 @@ describe('roadiehq:utils:jsonata:yaml:transform', () => {
);
});

it('should output string result of having applied the given transformation', async () => {
mock({
'fake-tmp-dir': {
'fake-file.yaml': 'hello: [world]',
},
});
await action.handler({
...mockContext,
workspacePath: 'fake-tmp-dir',
input: {
path: 'fake-file.yaml',
expression: '$ ~> | $ | { "hello": [hello, "item2"] }|',
as: 'string',
},
});

expect(mockContext.output).toHaveBeenCalledWith(
'result',
yaml.dump({ hello: ['world', 'item2'] }),
);
});

it('should pass options to yaml.dump', async () => {
mock({
'fake-tmp-dir': {
Expand Down Expand Up @@ -92,4 +114,25 @@ describe('roadiehq:utils:jsonata:yaml:transform', () => {

expect(mockDump).toHaveBeenCalledWith({ hello: 'beautiful world' }, opts);
});

it('should output object result of having applied the given transformation', async () => {
mock({
'fake-tmp-dir': {
'fake-file.yaml': 'hello: [world]',
},
});
await action.handler({
...mockContext,
workspacePath: 'fake-tmp-dir',
input: {
path: 'fake-file.yaml',
expression: '$ ~> | $ | { "hello": [hello, "item2"] }|',
as: 'object',
},
});

expect(mockContext.output).toHaveBeenCalledWith('result', {
hello: ['world', 'item2'],
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ export function createYamlJSONataTransformAction() {
path: string;
expression: string;
options?: supportedDumpOptions;
as?: 'string' | 'object';
}>({
id: 'roadiehq:utils:jsonata:yaml:transform',
description:
Expand All @@ -45,6 +46,13 @@ export function createYamlJSONataTransformAction() {
description: 'JSONata expression to perform on the input',
type: 'string',
},
as: {
title: 'Desired Result Type',
description:
'Permitted values are: "string" (default) and "object"',
type: 'string',
enum: ['string', 'object'],
},
options: yamlOptionsSchema,
},
},
Expand All @@ -53,22 +61,29 @@ export function createYamlJSONataTransformAction() {
properties: {
result: {
title: 'Output result from JSONata',
type: 'object',
type: 'object | string',
},
},
},
},
async handler(ctx) {
let resultHandler: (rz: any) => any;

if (ctx.input.as === 'object') {
resultHandler = rz => rz;
} else {
resultHandler = rz => yaml.dump(rz, ctx.input.options);
}
const sourceFilepath = resolveSafeChildPath(
ctx.workspacePath,
ctx.input.path,
);

const data = yaml.load(fs.readFileSync(sourceFilepath).toString());
const expression = jsonata(ctx.input.expression);
const result = yaml.dump(expression.evaluate(data), ctx.input.options);
const result = expression.evaluate(data);

ctx.output('result', result);
ctx.output('result', resultHandler(result));
},
});
}
40 changes: 13 additions & 27 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -25741,9 +25741,9 @@ semver-compare@^1.0.0:
integrity sha1-De4hahyUGrN+nvsXiPavxf9VN/w=

"semver@2 || 3 || 4 || 5", semver@^5.4.1, semver@^5.6.0:
version "5.7.1"
resolved "https://registry.yarnpkg.com/semver/-/semver-5.7.1.tgz#a954f931aeba508d307bbf069eff0c01c96116f7"
integrity sha512-sauaDf/PZdVgrLTNYHRtpXa1iRiKcaebiKQ1BJdpQlWH2lCvexQdX55snPFyK7QzpudqbCI0qXFfOasHdyNDGQ==
version "5.7.2"
resolved "https://registry.yarnpkg.com/semver/-/semver-5.7.2.tgz#48d55db737c3287cd4835e17fa13feace1c41ef8"
integrity sha512-cBznnQ9KjJqU67B52RMC65CMarK2600WFnbkcaiwWq3xy/5haFJlshgnpjovMVJ+Hff49d8GEn0b87C5pDQ10g==

[email protected]:
version "7.3.4"
Expand All @@ -25759,31 +25759,17 @@ [email protected]:
dependencies:
lru-cache "^6.0.0"

[email protected], semver@^7.1.1, semver@^7.2.1, semver@^7.3.2, semver@^7.3.4, semver@^7.3.5:
version "7.3.5"
resolved "https://registry.yarnpkg.com/semver/-/semver-7.3.5.tgz#0b621c879348d8998e4b0e4be94b3f12e6018ef7"
integrity sha512-PoeGJYh8HK4BTO/a9Tf6ZG3veo/A7ZVsYrSA6J8ny9nb3B1VrpkuN+z9OE5wfE5p6H4LchYZsegiQgbJD94ZFQ==
[email protected], semver@^7.0.0, semver@^7.1.1, semver@^7.1.2, semver@^7.2.1, semver@^7.3.2, semver@^7.3.4, semver@^7.3.5, semver@^7.3.7, semver@^7.3.8:
version "7.5.4"
resolved "https://registry.yarnpkg.com/semver/-/semver-7.5.4.tgz#483986ec4ed38e1c6c48c34894a9182dbff68a6e"
integrity sha512-1bCSESV6Pv+i21Hvpxp3Dx+pSD8lIPt8uVjRrxAUt/nbswYc+tK6Y2btiULjd4+fnq15PX+nqQDC7Oft7WkwcA==
dependencies:
lru-cache "^6.0.0"

semver@^6.0.0, semver@^6.1.1, semver@^6.1.2, semver@^6.3.0:
version "6.3.0"
resolved "https://registry.yarnpkg.com/semver/-/semver-6.3.0.tgz#ee0a64c8af5e8ceea67687b133761e1becbd1d3d"
integrity sha512-b39TBaTSfV6yBrapU89p5fKekE2m/NwnDocOVruQFS1/veMgdzuPcnOM34M6CwxW8jH/lxEa5rBoDeUwu5HHTw==

semver@^7.0.0, semver@^7.1.2, semver@^7.3.7:
version "7.3.7"
resolved "https://registry.yarnpkg.com/semver/-/semver-7.3.7.tgz#12c5b649afdbf9049707796e22a4028814ce523f"
integrity sha512-QlYTucUYOews+WeEujDoEGziz4K6c47V/Bd+LjSSYcA94p+DmINdf7ncaUinThfvZyu13lN9OY1XDxt8C0Tw0g==
dependencies:
lru-cache "^6.0.0"

semver@^7.3.8:
version "7.5.0"
resolved "https://registry.yarnpkg.com/semver/-/semver-7.5.0.tgz#ed8c5dc8efb6c629c88b23d41dc9bf40c1d96cd0"
integrity sha512-+XC0AD/R7Q2mPSRuy2Id0+CGTZ98+8f+KvwirxOKIEyid+XSx6HbC63p+O4IndTHuX5Z+JxQ0TghCkO5Cg/2HA==
dependencies:
lru-cache "^6.0.0"
version "6.3.1"
resolved "https://registry.yarnpkg.com/semver/-/semver-6.3.1.tgz#556d2ef8689146e46dcea4bfdd095f3434dffcb4"
integrity sha512-BR7VvDCVHO+q2xBEWskxS6DJE1qRnb7DxzUrogb71CWoSficBxYsiAGd+Kl0mmq/MprG9yArRkyrQxTO6XjMzA==

[email protected]:
version "0.17.2"
Expand Down Expand Up @@ -28498,9 +28484,9 @@ winston@^3.2.1:
winston-transport "^4.5.0"

word-wrap@^1.2.3, word-wrap@~1.2.3:
version "1.2.3"
resolved "https://registry.yarnpkg.com/word-wrap/-/word-wrap-1.2.3.tgz#610636f6b1f703891bd34771ccb17fb93b47079c"
integrity sha512-Hz/mrNwitNRh/HUAtM/VT/5VH+ygD6DV7mYKZAtHOrbs8U7lvPS6xf7EJKMF0uW1KJCl0H701g3ZGus+muE5vQ==
version "1.2.4"
resolved "https://registry.yarnpkg.com/word-wrap/-/word-wrap-1.2.4.tgz#cb4b50ec9aca570abd1f52f33cd45b6c61739a9f"
integrity sha512-2V81OA4ugVo5pRo46hAoD2ivUJx8jXmWXfUkY4KFNw0hEptvN0QfH3K4nHiwzGeKl5rFKedV48QVoqYavy4YpA==

wordwrap@^1.0.0:
version "1.0.0"
Expand Down

0 comments on commit 602ea41

Please sign in to comment.