diff --git a/apps/webapp/app/routes/_app.orgs.$organizationSlug.projects.$projectParam.env.$envParam.alerts.new/route.tsx b/apps/webapp/app/routes/_app.orgs.$organizationSlug.projects.$projectParam.env.$envParam.alerts.new/route.tsx index 7d3ef9b7c9..e408d82aa5 100644 --- a/apps/webapp/app/routes/_app.orgs.$organizationSlug.projects.$projectParam.env.$envParam.alerts.new/route.tsx +++ b/apps/webapp/app/routes/_app.orgs.$organizationSlug.projects.$projectParam.env.$envParam.alerts.new/route.tsx @@ -50,9 +50,9 @@ const FormSchema = z .min(1) .or(z.enum(["TASK_RUN", "DEPLOYMENT_FAILURE", "DEPLOYMENT_SUCCESS"])), environmentTypes: z - .array(z.enum(["STAGING", "PRODUCTION"])) + .array(z.enum(["STAGING", "PRODUCTION", "PREVIEW"])) .min(1) - .or(z.enum(["STAGING", "PRODUCTION"])), + .or(z.enum(["STAGING", "PRODUCTION", "PREVIEW"])), type: z.enum(["WEBHOOK", "SLACK", "EMAIL"]).default("EMAIL"), channelValue: z.string().nonempty(), integrationId: z.string().optional(), @@ -441,7 +441,7 @@ export default function Page() { - + {environmentTypes.error} {form.error} diff --git a/apps/webapp/app/v3/services/alerts/deliverAlert.server.ts b/apps/webapp/app/v3/services/alerts/deliverAlert.server.ts index 65ad55cc64..d9c6236d3f 100644 --- a/apps/webapp/app/v3/services/alerts/deliverAlert.server.ts +++ b/apps/webapp/app/v3/services/alerts/deliverAlert.server.ts @@ -40,6 +40,7 @@ import { type ProjectAlertChannelType, type ProjectAlertType } from "@trigger.de import { alertsRateLimiter } from "~/v3/alertsRateLimiter.server"; import { v3RunPath } from "~/utils/pathBuilder"; import { ApiRetrieveRunPresenter } from "~/presenters/v3/ApiRetrieveRunPresenter.server"; +import { environmentTitle } from "~/components/environments/EnvironmentLabel"; type FoundAlert = Prisma.Result< typeof prisma.projectAlert, @@ -56,6 +57,12 @@ type FoundAlert = Prisma.Result< include: { lockedBy: true; lockedToVersion: true; + runtimeEnvironment: { + select: { + type: true; + branchName: true; + }; + }; }; }; workerDeployment: { @@ -65,6 +72,12 @@ type FoundAlert = Prisma.Result< tasks: true; }; }; + environment: { + select: { + type: true; + branchName: true; + }; + }; }; }; }; @@ -90,6 +103,12 @@ export class DeliverAlertService extends BaseService { include: { lockedBy: true, lockedToVersion: true, + runtimeEnvironment: { + select: { + type: true, + branchName: true, + }, + }, }, }, workerDeployment: { @@ -99,6 +118,12 @@ export class DeliverAlertService extends BaseService { tasks: true, }, }, + environment: { + select: { + type: true, + branchName: true, + }, + }, }, }, }, @@ -177,10 +202,9 @@ export class DeliverAlertService extends BaseService { runId: alert.taskRun.friendlyId, taskIdentifier: alert.taskRun.taskIdentifier, fileName: alert.taskRun.lockedBy?.filePath ?? "Unknown", - exportName: alert.taskRun.lockedBy?.exportName ?? "Unknown", version: alert.taskRun.lockedToVersion?.version ?? "Unknown", project: alert.project.name, - environment: alert.environment.slug, + environment: environmentTitle(alert.taskRun.runtimeEnvironment), error: createJsonErrorObject(taskRunError), runLink: `${env.APP_ORIGIN}/projects/v3/${alert.project.externalRef}/runs/${alert.taskRun.friendlyId}`, organization: alert.project.organization.title, @@ -211,7 +235,7 @@ export class DeliverAlertService extends BaseService { email: "alert-deployment-failure", to: emailProperties.data.email, version: alert.workerDeployment.version, - environment: alert.environment.slug, + environment: environmentTitle(alert.workerDeployment.environment), shortCode: alert.workerDeployment.shortCode, failedAt: alert.workerDeployment.failedAt ?? new Date(), error: preparedError, @@ -232,7 +256,7 @@ export class DeliverAlertService extends BaseService { email: "alert-deployment-success", to: emailProperties.data.email, version: alert.workerDeployment.version, - environment: alert.environment.slug, + environment: environmentTitle(alert.workerDeployment.environment), shortCode: alert.workerDeployment.shortCode, deployedAt: alert.workerDeployment.deployedAt ?? new Date(), deploymentLink: `${env.APP_ORIGIN}/projects/v3/${alert.project.externalRef}/deployments/${alert.workerDeployment.shortCode}`, @@ -292,6 +316,7 @@ export class DeliverAlertService extends BaseService { id: alert.environment.id, type: alert.environment.type, slug: alert.environment.slug, + branchName: alert.environment.branchName ?? undefined, }, organization: { id: alert.project.organizationId, @@ -349,6 +374,7 @@ export class DeliverAlertService extends BaseService { id: alert.environment.id, type: alert.environment.type, slug: alert.environment.slug, + branchName: alert.environment.branchName ?? undefined, }, organization: { id: alert.project.organizationId, @@ -648,9 +674,8 @@ export class DeliverAlertService extends BaseService { const taskRunError = this.#getRunError(alert); const error = createJsonErrorObject(taskRunError); - const exportName = alert.taskRun.lockedBy?.exportName ?? "Unknown"; const version = alert.taskRun.lockedToVersion?.version ?? "Unknown"; - const environment = alert.environment.slug; + const environment = environmentTitle(alert.taskRun.runtimeEnvironment); const taskIdentifier = alert.taskRun.taskIdentifier; const timestamp = alert.taskRun.completedAt ?? new Date(); const runId = alert.taskRun.friendlyId; @@ -664,7 +689,7 @@ export class DeliverAlertService extends BaseService { type: "section", text: { type: "mrkdwn", - text: `:rotating_light: Error in *${exportName}* __`, }, diff --git a/apps/webapp/app/v3/services/alerts/performTaskRunAlerts.server.ts b/apps/webapp/app/v3/services/alerts/performTaskRunAlerts.server.ts index 370dd34c7c..0f8f90d89d 100644 --- a/apps/webapp/app/v3/services/alerts/performTaskRunAlerts.server.ts +++ b/apps/webapp/app/v3/services/alerts/performTaskRunAlerts.server.ts @@ -16,7 +16,11 @@ export class PerformTaskRunAlertsService extends BaseService { where: { id: runId }, include: { lockedBy: true, - runtimeEnvironment: true, + runtimeEnvironment: { + include: { + parentEnvironment: true, + }, + }, }, }); @@ -32,7 +36,7 @@ export class PerformTaskRunAlertsService extends BaseService { has: "TASK_RUN", }, environmentTypes: { - has: run.runtimeEnvironment.type, + has: run.runtimeEnvironment.parentEnvironment?.type ?? run.runtimeEnvironment.type, }, enabled: true, }, diff --git a/internal-packages/emails/emails/alert-run-failure.tsx b/internal-packages/emails/emails/alert-run-failure.tsx index 4cdceba6bf..6694da1fbd 100644 --- a/internal-packages/emails/emails/alert-run-failure.tsx +++ b/internal-packages/emails/emails/alert-run-failure.tsx @@ -21,7 +21,6 @@ export const AlertRunEmailSchema = z.object({ project: z.string(), taskIdentifier: z.string(), fileName: z.string(), - exportName: z.string(), version: z.string(), environment: z.string(), error: z.object({ @@ -41,7 +40,6 @@ const previewDefaults: AlertRunEmailProps = { project: "my-project", taskIdentifier: "my-task", fileName: "other.ts", - exportName: "myTask", version: "20240101.1", environment: "prod", error: { @@ -59,7 +57,6 @@ export default function Email(props: AlertRunEmailProps) { project, taskIdentifier, fileName, - exportName, version, environment, error, @@ -81,7 +78,6 @@ export default function Email(props: AlertRunEmailProps) { Project: {project} Task ID: {taskIdentifier} Filename: {fileName} - Function: {exportName}() Version: {version} Environment: {environment} diff --git a/packages/core/src/v3/schemas/webhooks.ts b/packages/core/src/v3/schemas/webhooks.ts index e619ffe97c..5c45727dc5 100644 --- a/packages/core/src/v3/schemas/webhooks.ts +++ b/packages/core/src/v3/schemas/webhooks.ts @@ -56,6 +56,8 @@ const AlertWebhookRunFailedObject = z.object({ type: RuntimeEnvironmentTypeSchema, /** Environment slug */ slug: z.string(), + /** Environment branch name */ + branchName: z.string().optional(), }), /** Organization information */ organization: z.object({ @@ -99,6 +101,8 @@ const deploymentCommonProperties = { id: z.string(), type: RuntimeEnvironmentTypeSchema, slug: z.string(), + /** Environment branch name */ + branchName: z.string().optional(), }), /** Organization information */ organization: z.object({