Skip to content

Commit

Permalink
Add approval and approval approver to openapi spec and get-job-inputs
Browse files Browse the repository at this point in the history
  • Loading branch information
zacharyblasczyk committed Oct 27, 2024
1 parent a85a25e commit 629d1a8
Show file tree
Hide file tree
Showing 9 changed files with 394 additions and 9 deletions.
117 changes: 114 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.

9 changes: 9 additions & 0 deletions integrations/github-get-job-inputs/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ async function run() {
runbook,
deployment,
causedBy,
approval,
} = response;

setOutputAndLog("base_url", baseUrl);
Expand Down Expand Up @@ -86,6 +87,14 @@ async function run() {
setOutputAndLog("caused_by_name", causedBy.name);
setOutputAndLog("caused_by_email", causedBy.email);

setOutputAndLog("approval_status", approval.status);
setOutputAndLog("approval_approver_id", approval.approver?.id ?? "");
setOutputAndLog("approval_approver_name", approval.approver?.name ?? "");
setOutputAndLog(
"approval_approver_email",
approval.approver?.email ?? "",
);

setOutputAndLog("deployment_id", deployment?.id);
setOutputAndLog("deployment_name", deployment?.name);
setOutputAndLog("deployment_slug", deployment?.slug);
Expand Down
30 changes: 29 additions & 1 deletion openapi.v1.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -402,13 +402,41 @@ paths:
- id
- name
- email
approval:
type: object
nullable: true
properties:
id:
type: string
status:
type: string
enum: [pending, approved, rejected]
approver:
type: object
nullable: true
description: Null when status is pending, contains approver details when approved or rejected
properties:
id:
type: string
name:
type: string
email:
type: string
required:
- id
- name
- email
required:
- id
- status
required:
- id
- status
- createdAt
- updatedAt
- variable
- variables
- causedBy
- approval
patch:
summary: Update a job
operationId: updateJob
Expand Down
32 changes: 29 additions & 3 deletions packages/api/src/router/job.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import type {
Deployment,
Environment,
EnvironmentPolicy,
EnvironmentPolicyApproval,
EnvironmentPolicyReleaseWindow,
Job,
JobAgent,
Expand All @@ -19,11 +20,13 @@ import { isPresent } from "ts-is-present";
import { z } from "zod";

import {
alias,
and,
asc,
desc,
eq,
inArray,
isNotNull,
isNull,
notInArray,
sql,
Expand All @@ -34,6 +37,7 @@ import {
deployment,
environment,
environmentPolicy,
environmentPolicyApproval,
environmentPolicyReleaseWindow,
job,
jobAgent,
Expand All @@ -60,16 +64,30 @@ import { JobStatus } from "@ctrlplane/validators/jobs";

import { createTRPCRouter, protectedProcedure } from "../trpc";

const releaseJobTriggerQuery = (tx: Tx) =>
tx
const releaseJobTriggerQuery = (tx: Tx) => {
const approver = alias(user, "approver");

return tx
.select()
.from(releaseJobTrigger)
.innerJoin(job, eq(releaseJobTrigger.jobId, job.id))
.innerJoin(target, eq(releaseJobTrigger.targetId, target.id))
.innerJoin(release, eq(releaseJobTrigger.releaseId, release.id))
.innerJoin(deployment, eq(release.deploymentId, deployment.id))
.innerJoin(environment, eq(releaseJobTrigger.environmentId, environment.id))
.innerJoin(jobAgent, eq(jobAgent.id, deployment.jobAgentId));
.innerJoin(jobAgent, eq(jobAgent.id, deployment.jobAgentId))
.leftJoin(
environmentPolicyApproval,
eq(environmentPolicyApproval.releaseId, release.id),
)
.leftJoin(
approver,
and(
isNotNull(environmentPolicyApproval.userId),
eq(environmentPolicyApproval.userId, approver.id),
),
);
};

const processReleaseJobTriggerWithAdditionalDataRows = (
rows: Array<{
Expand All @@ -87,6 +105,8 @@ const processReleaseJobTriggerWithAdditionalDataRows = (
release_dependency?: ReleaseDependency | null;
deployment_name?: { deploymentName: string; deploymentId: string } | null;
job_variable?: JobVariable | null;
environment_policy_approval: EnvironmentPolicyApproval | null;
approver?: User | null;
}>,
) =>
_.chain(rows)
Expand Down Expand Up @@ -127,6 +147,12 @@ const processReleaseJobTriggerWithAdditionalDataRows = (
.filter(isPresent),
)
: null,
approval: v[0]!.environment_policy_approval
? {
...v[0]!.environment_policy_approval,
approver: v[0]!.approver,
}
: null,
}))
.value();

Expand Down
2 changes: 2 additions & 0 deletions packages/node-sdk/src/.openapi-generator/FILES
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ models/CreateRelease200Response.ts
models/CreateReleaseRequest.ts
models/GetAgentRunningJob200ResponseInner.ts
models/GetJob200Response.ts
models/GetJob200ResponseApproval.ts
models/GetJob200ResponseApprovalApprover.ts
models/GetJob200ResponseCausedBy.ts
models/GetJob200ResponseDeployment.ts
models/GetJob200ResponseEnvironment.ts
Expand Down
20 changes: 18 additions & 2 deletions packages/node-sdk/src/models/GetJob200Response.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,19 @@
* Do not edit the class manually.
*/

import type { GetJob200ResponseApproval } from "./GetJob200ResponseApproval";
import type { GetJob200ResponseCausedBy } from "./GetJob200ResponseCausedBy";
import type { GetJob200ResponseDeployment } from "./GetJob200ResponseDeployment";
import type { GetJob200ResponseEnvironment } from "./GetJob200ResponseEnvironment";
import type { GetJob200ResponseRelease } from "./GetJob200ResponseRelease";
import type { GetJob200ResponseRunbook } from "./GetJob200ResponseRunbook";
import type { GetJob200ResponseTarget } from "./GetJob200ResponseTarget";
import { mapValues } from "../runtime";
import {
GetJob200ResponseApprovalFromJSON,
GetJob200ResponseApprovalFromJSONTyped,
GetJob200ResponseApprovalToJSON,
} from "./GetJob200ResponseApproval";
import {
GetJob200ResponseCausedByFromJSON,
GetJob200ResponseCausedByFromJSONTyped,
Expand Down Expand Up @@ -103,13 +109,19 @@ export interface GetJob200Response {
* @type {object}
* @memberof GetJob200Response
*/
variables?: object;
variables: object;
/**
*
* @type {GetJob200ResponseCausedBy}
* @memberof GetJob200Response
*/
causedBy: GetJob200ResponseCausedBy;
/**
*
* @type {GetJob200ResponseApproval}
* @memberof GetJob200Response
*/
approval: GetJob200ResponseApproval;
}

/**
Expand Down Expand Up @@ -138,7 +150,9 @@ export function instanceOfGetJob200Response(
): value is GetJob200Response {
if (!("id" in value) || value["id"] === undefined) return false;
if (!("status" in value) || value["status"] === undefined) return false;
if (!("variables" in value) || value["variables"] === undefined) return false;
if (!("causedBy" in value) || value["causedBy"] === undefined) return false;
if (!("approval" in value) || value["approval"] === undefined) return false;
return true;
}

Expand Down Expand Up @@ -176,8 +190,9 @@ export function GetJob200ResponseFromJSONTyped(
json["environment"] == null
? undefined
: GetJob200ResponseEnvironmentFromJSON(json["environment"]),
variables: json["variables"] == null ? undefined : json["variables"],
variables: json["variables"],
causedBy: GetJob200ResponseCausedByFromJSON(json["causedBy"]),
approval: GetJob200ResponseApprovalFromJSON(json["approval"]),
};
}

Expand All @@ -195,5 +210,6 @@ export function GetJob200ResponseToJSON(value?: GetJob200Response | null): any {
environment: GetJob200ResponseEnvironmentToJSON(value["environment"]),
variables: value["variables"],
causedBy: GetJob200ResponseCausedByToJSON(value["causedBy"]),
approval: GetJob200ResponseApprovalToJSON(value["approval"]),
};
}
Loading

0 comments on commit 629d1a8

Please sign in to comment.