Skip to content

Commit

Permalink
Add option to remove temporary integration and component after a comp…
Browse files Browse the repository at this point in the history
…onent:dev:test (#22)

* Add option to remove temporary integration and component after a component:dev:test

* PR Feedback
  • Loading branch information
taylorreece authored May 30, 2023
1 parent d97ccd9 commit 9027550
Show file tree
Hide file tree
Showing 7 changed files with 90 additions and 8 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@prismatic-io/prism",
"version": "4.6.3",
"version": "4.6.4",
"description": "Build, deploy, and support integrations in Prismatic from the comfort of your command line",
"keywords": [
"prismatic",
Expand Down Expand Up @@ -163,4 +163,4 @@
}
}
}
}
}
23 changes: 22 additions & 1 deletion src/commands/components/dev/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,10 @@ import {
ComponentTestInfo,
} from "../../../utils/integration/definition";
import { importDefinition } from "../../../utils/integration/import";
import { runIntegrationFlow } from "../../../utils/integration/invoke";
import {
deleteIntegration,
runIntegrationFlow,
} from "../../../utils/integration/invoke";
import { pollForActiveConfigVarState } from "../../../utils/integration/query";
import { Expression } from "../../../utils/integration/export";
import { exists } from "../../../fs";
Expand All @@ -30,6 +33,7 @@ import {
printFinalStepResults,
writeFinalStepResults,
} from "../../../utils/execution/stepResults";
import { deleteComponentByKey } from "../../../utils/component/deleteByKey";

const setTimeoutPromise = promisify(setTimeout);

Expand Down Expand Up @@ -168,6 +172,12 @@ export default class TestCommand extends Command {
default: false,
description: "Print the results of the action to stdout",
}),
"clean-up": Flags.boolean({
required: false,
default: false,
description:
"Clean up the integration and temporary component after running the action",
}),
};

async run() {
Expand All @@ -177,6 +187,7 @@ export default class TestCommand extends Command {
build,
"output-file": outputFile,
"print-results": printResults,
"clean-up": cleanUp,
},
} = await this.parse(TestCommand);

Expand Down Expand Up @@ -379,6 +390,16 @@ export default class TestCommand extends Command {
await printFinalStepResults(executionId);
}

if (cleanUp) {
CliUx.ux.action.start(`Cleaning up test Integration (${integrationId})`);
await deleteIntegration(integrationId);
CliUx.ux.action.stop();

CliUx.ux.action.start(`Cleaning up test component (${definition.key})`);
await deleteComponentByKey(definition.key);
CliUx.ux.action.stop();
}

CliUx.ux.action.stop();
}
}
3 changes: 2 additions & 1 deletion src/commands/instances/create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ export default class CreateCommand extends Command {
integration: Flags.string({
char: "i",
required: true,
description: "ID of the integration or a specific integration version ID this is an instance of",
description:
"ID of the integration or a specific integration version ID this is an instance of",
}),
customer: Flags.string({
char: "c",
Expand Down
14 changes: 12 additions & 2 deletions src/commands/instances/update.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,19 @@ export default class UpdateCommand extends Command {

const result = await gqlRequest({
document: gql`
mutation updateInstance($id: ID!, $name: String, $description: String, $version: ID! ) {
mutation updateInstance(
$id: ID!
$name: String
$description: String
$version: ID!
) {
updateInstance(
input: { id: $id, name: $name, description: $description, integration: $version}
input: {
id: $id
name: $name
description: $description
integration: $version
}
) {
instance {
id
Expand Down
33 changes: 33 additions & 0 deletions src/utils/component/deleteByKey.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import { gql, gqlRequest } from "../../graphql";

export const deleteComponentByKey = async (key: string) => {
// Fetch a component by key
const result = await gqlRequest({
document: gql`
query component($key: String!) {
components(key: $key, public: false) {
nodes {
id
}
}
}
`,
variables: {
key,
},
});
// Delete the component by ID
await gqlRequest({
document: gql`
mutation deleteComponent($id: ID!) {
deleteComponent(input: { id: $id }) {
errors {
field
messages
}
}
}
`,
variables: { id: result.components.nodes[0].id },
});
};
17 changes: 17 additions & 0 deletions src/utils/integration/invoke.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,23 @@ export const getIntegrationFlow = async (
return flows[0].id;
};

/** Delete a specified integration by ID */
export const deleteIntegration = async (integrationId: string) => {
await gqlRequest({
document: gql`
mutation deleteIntegration($id: ID!) {
deleteIntegration(input: { id: $id }) {
errors {
field
messages
}
}
}
`,
variables: { id: integrationId },
});
};

interface IntegrationFlowRunProps {
integrationId: string;
flowId?: string;
Expand Down

0 comments on commit 9027550

Please sign in to comment.