Skip to content

Commit

Permalink
fix: Job output includes release metadata
Browse files Browse the repository at this point in the history
  • Loading branch information
adityachoudhari26 committed Dec 10, 2024
1 parent c41c77e commit 13aba3b
Show file tree
Hide file tree
Showing 3 changed files with 1,814 additions and 1,782 deletions.
22 changes: 18 additions & 4 deletions apps/webservice/src/app/api/v1/jobs/[jobId]/route.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import type { NextRequest } from "next/server";
import { NextResponse } from "next/server";
import { isPresent } from "ts-is-present";

import { and, eq, isNull, takeFirstOrNull } from "@ctrlplane/db";
import { db } from "@ctrlplane/db/client";
Expand Down Expand Up @@ -58,7 +59,7 @@ export const GET = request()
}),
)
.handle<object, { params: { jobId: string } }>(async ({ db }, { params }) => {
const row = await db
const rows = await db
.select()
.from(schema.job)
.leftJoin(
Expand All @@ -85,28 +86,41 @@ export const GET = request()
schema.release,
eq(schema.releaseJobTrigger.releaseId, schema.release.id),
)
.leftJoin(
schema.releaseMetadata,
eq(schema.release.id, schema.releaseMetadata.releaseId),
)
.leftJoin(
schema.deployment,
eq(schema.release.deploymentId, schema.deployment.id),
)
.where(
and(eq(schema.job.id, params.jobId), isNull(schema.resource.deletedAt)),
)
.then(takeFirstOrNull);
);

const row = rows.at(0);

if (row == null)
return NextResponse.json(
{ error: "Job execution not found." },
{ status: 404 },
);

const release =
row.release != null
? {
...row.release,
metadata: rows.map((r) => r.release_metadata).filter(isPresent),
}
: null;

const je = {
job: row.job,
runbook: row.runbook,
environment: row.environment,
resource: row.resource,
deployment: row.deployment,
release: row.release,
release,
};

const policyId = je.environment?.policyId;
Expand Down
5 changes: 5 additions & 0 deletions openapi.v1.json
Original file line number Diff line number Diff line change
Expand Up @@ -2355,6 +2355,10 @@
"type": "object",
"additionalProperties": true
},
"metadata": {
"type": "object",
"additionalProperties": { "type": "string" }
},
"deploymentId": {
"type": "string",
"format": "uuid"
Expand All @@ -2369,6 +2373,7 @@
"name",
"version",
"config",
"metadata",
"deploymentId",
"createdAt"
]
Expand Down
Loading

0 comments on commit 13aba3b

Please sign in to comment.