Skip to content

Commit

Permalink
Target Metadata for get-job-inputs (#88)
Browse files Browse the repository at this point in the history
  • Loading branch information
zacharyblasczyk authored Oct 1, 2024
1 parent 17e8a99 commit ff97dd2
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 6 deletions.
22 changes: 21 additions & 1 deletion apps/webservice/src/app/api/v1/jobs/[jobId]/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
runbook,
runbookJobTrigger,
target,
targetMetadata,
updateJob,
} from "@ctrlplane/db/schema";
import { onJobCompletion } from "@ctrlplane/job-dispatch";
Expand Down Expand Up @@ -58,7 +59,26 @@ export const GET = async (
jobVariableRows.map((v) => [v.key, v.value]),
);

return NextResponse.json({ ...je.job, ...je, variables });
const jobTargetMetadataRows = await db
.select()
.from(targetMetadata)
.where(eq(targetMetadata.targetId, je.target?.id ?? ""));

const metadata = Object.fromEntries(
jobTargetMetadataRows.map((m) => [m.key, m.value]),
);

const targetWithMetadata = {
...je.target,
metadata,
};

return NextResponse.json({
...je.job,
...je,
variables,
target: targetWithMetadata,
});
};

const bodySchema = updateJob;
Expand Down
10 changes: 7 additions & 3 deletions github/get-job-inputs/index.js

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

3 changes: 2 additions & 1 deletion integrations/get-job-inputs/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ const setOutputAndLog = (key: string, value: any) => {
const setOutputsRecursively = (prefix: string, obj: any) => {
if (typeof obj === "object" && obj !== null) {
for (const [key, value] of Object.entries(obj)) {
const sanitizedKey = key.split(".").join("_");
const sanitizedKey = key.replace(/[.\-/\s\t]+/g, "_");
const newPrefix = prefix ? `${prefix}_${sanitizedKey}` : sanitizedKey;
if (typeof value === "object" && value !== null)
setOutputsRecursively(newPrefix, value);
Expand Down Expand Up @@ -59,6 +59,7 @@ async function run() {
setOutputAndLog("target_version", target?.version);
setOutputAndLog("target_identifier", target?.identifier);
setOutputsRecursively("target_config", target?.config);
setOutputsRecursively("target_metadata", target?.metadata);

setOutputAndLog("workspace_id", target?.workspaceId);

Expand Down
11 changes: 10 additions & 1 deletion packages/node-sdk/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -337,8 +337,17 @@ paths:
type: string
config:
type: object
metadata:
type: object
required:
[id, name, version, kind, identifier, workspaceId, config]
- id
- name
- version
- kind
- identifier
- workspaceId
- config
- metadata

environment:
type: object
Expand Down
9 changes: 9 additions & 0 deletions packages/node-sdk/src/models/GetJob200ResponseTarget.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,12 @@ export interface GetJob200ResponseTarget {
* @memberof GetJob200ResponseTarget
*/
config: object;
/**
*
* @type {object}
* @memberof GetJob200ResponseTarget
*/
metadata: object;
}

/**
Expand All @@ -79,6 +85,7 @@ export function instanceOfGetJob200ResponseTarget(
if (!("workspaceId" in value) || value["workspaceId"] === undefined)
return false;
if (!("config" in value) || value["config"] === undefined) return false;
if (!("metadata" in value) || value["metadata"] === undefined) return false;
return true;
}

Expand All @@ -103,6 +110,7 @@ export function GetJob200ResponseTargetFromJSONTyped(
identifier: json["identifier"],
workspaceId: json["workspaceId"],
config: json["config"],
metadata: json["metadata"],
};
}

Expand All @@ -120,5 +128,6 @@ export function GetJob200ResponseTargetToJSON(
identifier: value["identifier"],
workspaceId: value["workspaceId"],
config: value["config"],
metadata: value["metadata"],
};
}

0 comments on commit ff97dd2

Please sign in to comment.