Skip to content

Commit 80d449b

Browse files
authored
Preview branch alerts (#2136)
* Preview branch alerts * Show “Preview” not the branch for new alert modal
1 parent ff157e5 commit 80d449b

File tree

5 files changed

+45
-16
lines changed

5 files changed

+45
-16
lines changed

apps/webapp/app/routes/_app.orgs.$organizationSlug.projects.$projectParam.env.$envParam.alerts.new/route.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,9 @@ const FormSchema = z
5050
.min(1)
5151
.or(z.enum(["TASK_RUN", "DEPLOYMENT_FAILURE", "DEPLOYMENT_SUCCESS"])),
5252
environmentTypes: z
53-
.array(z.enum(["STAGING", "PRODUCTION"]))
53+
.array(z.enum(["STAGING", "PRODUCTION", "PREVIEW"]))
5454
.min(1)
55-
.or(z.enum(["STAGING", "PRODUCTION"])),
55+
.or(z.enum(["STAGING", "PRODUCTION", "PREVIEW"])),
5656
type: z.enum(["WEBHOOK", "SLACK", "EMAIL"]).default("EMAIL"),
5757
channelValue: z.string().nonempty(),
5858
integrationId: z.string().optional(),
@@ -441,7 +441,7 @@ export default function Page() {
441441
<InputGroup>
442442
<Label>Environment</Label>
443443
<input type="hidden" name={environmentTypes.name} value={environment.type} />
444-
<EnvironmentCombo environment={environment} />
444+
<EnvironmentCombo environment={{ type: environment.type }} />
445445
<FormError id={environmentTypes.errorId}>{environmentTypes.error}</FormError>
446446
</InputGroup>
447447
<FormError>{form.error}</FormError>

apps/webapp/app/v3/services/alerts/deliverAlert.server.ts

Lines changed: 32 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ import { type ProjectAlertChannelType, type ProjectAlertType } from "@trigger.de
4040
import { alertsRateLimiter } from "~/v3/alertsRateLimiter.server";
4141
import { v3RunPath } from "~/utils/pathBuilder";
4242
import { ApiRetrieveRunPresenter } from "~/presenters/v3/ApiRetrieveRunPresenter.server";
43+
import { environmentTitle } from "~/components/environments/EnvironmentLabel";
4344

4445
type FoundAlert = Prisma.Result<
4546
typeof prisma.projectAlert,
@@ -56,6 +57,12 @@ type FoundAlert = Prisma.Result<
5657
include: {
5758
lockedBy: true;
5859
lockedToVersion: true;
60+
runtimeEnvironment: {
61+
select: {
62+
type: true;
63+
branchName: true;
64+
};
65+
};
5966
};
6067
};
6168
workerDeployment: {
@@ -65,6 +72,12 @@ type FoundAlert = Prisma.Result<
6572
tasks: true;
6673
};
6774
};
75+
environment: {
76+
select: {
77+
type: true;
78+
branchName: true;
79+
};
80+
};
6881
};
6982
};
7083
};
@@ -90,6 +103,12 @@ export class DeliverAlertService extends BaseService {
90103
include: {
91104
lockedBy: true,
92105
lockedToVersion: true,
106+
runtimeEnvironment: {
107+
select: {
108+
type: true,
109+
branchName: true,
110+
},
111+
},
93112
},
94113
},
95114
workerDeployment: {
@@ -99,6 +118,12 @@ export class DeliverAlertService extends BaseService {
99118
tasks: true,
100119
},
101120
},
121+
environment: {
122+
select: {
123+
type: true,
124+
branchName: true,
125+
},
126+
},
102127
},
103128
},
104129
},
@@ -177,10 +202,9 @@ export class DeliverAlertService extends BaseService {
177202
runId: alert.taskRun.friendlyId,
178203
taskIdentifier: alert.taskRun.taskIdentifier,
179204
fileName: alert.taskRun.lockedBy?.filePath ?? "Unknown",
180-
exportName: alert.taskRun.lockedBy?.exportName ?? "Unknown",
181205
version: alert.taskRun.lockedToVersion?.version ?? "Unknown",
182206
project: alert.project.name,
183-
environment: alert.environment.slug,
207+
environment: environmentTitle(alert.taskRun.runtimeEnvironment),
184208
error: createJsonErrorObject(taskRunError),
185209
runLink: `${env.APP_ORIGIN}/projects/v3/${alert.project.externalRef}/runs/${alert.taskRun.friendlyId}`,
186210
organization: alert.project.organization.title,
@@ -211,7 +235,7 @@ export class DeliverAlertService extends BaseService {
211235
email: "alert-deployment-failure",
212236
to: emailProperties.data.email,
213237
version: alert.workerDeployment.version,
214-
environment: alert.environment.slug,
238+
environment: environmentTitle(alert.workerDeployment.environment),
215239
shortCode: alert.workerDeployment.shortCode,
216240
failedAt: alert.workerDeployment.failedAt ?? new Date(),
217241
error: preparedError,
@@ -232,7 +256,7 @@ export class DeliverAlertService extends BaseService {
232256
email: "alert-deployment-success",
233257
to: emailProperties.data.email,
234258
version: alert.workerDeployment.version,
235-
environment: alert.environment.slug,
259+
environment: environmentTitle(alert.workerDeployment.environment),
236260
shortCode: alert.workerDeployment.shortCode,
237261
deployedAt: alert.workerDeployment.deployedAt ?? new Date(),
238262
deploymentLink: `${env.APP_ORIGIN}/projects/v3/${alert.project.externalRef}/deployments/${alert.workerDeployment.shortCode}`,
@@ -292,6 +316,7 @@ export class DeliverAlertService extends BaseService {
292316
id: alert.environment.id,
293317
type: alert.environment.type,
294318
slug: alert.environment.slug,
319+
branchName: alert.environment.branchName ?? undefined,
295320
},
296321
organization: {
297322
id: alert.project.organizationId,
@@ -349,6 +374,7 @@ export class DeliverAlertService extends BaseService {
349374
id: alert.environment.id,
350375
type: alert.environment.type,
351376
slug: alert.environment.slug,
377+
branchName: alert.environment.branchName ?? undefined,
352378
},
353379
organization: {
354380
id: alert.project.organizationId,
@@ -648,9 +674,8 @@ export class DeliverAlertService extends BaseService {
648674
const taskRunError = this.#getRunError(alert);
649675
const error = createJsonErrorObject(taskRunError);
650676

651-
const exportName = alert.taskRun.lockedBy?.exportName ?? "Unknown";
652677
const version = alert.taskRun.lockedToVersion?.version ?? "Unknown";
653-
const environment = alert.environment.slug;
678+
const environment = environmentTitle(alert.taskRun.runtimeEnvironment);
654679
const taskIdentifier = alert.taskRun.taskIdentifier;
655680
const timestamp = alert.taskRun.completedAt ?? new Date();
656681
const runId = alert.taskRun.friendlyId;
@@ -664,7 +689,7 @@ export class DeliverAlertService extends BaseService {
664689
type: "section",
665690
text: {
666691
type: "mrkdwn",
667-
text: `:rotating_light: Error in *${exportName}* _<!date^${Math.round(
692+
text: `:rotating_light: Error in *${taskIdentifier}* _<!date^${Math.round(
668693
timestamp.getTime() / 1000
669694
)}^at {date_num} {time_secs}|${timestamp.toLocaleString()}>_`,
670695
},

apps/webapp/app/v3/services/alerts/performTaskRunAlerts.server.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,11 @@ export class PerformTaskRunAlertsService extends BaseService {
1616
where: { id: runId },
1717
include: {
1818
lockedBy: true,
19-
runtimeEnvironment: true,
19+
runtimeEnvironment: {
20+
include: {
21+
parentEnvironment: true,
22+
},
23+
},
2024
},
2125
});
2226

@@ -32,7 +36,7 @@ export class PerformTaskRunAlertsService extends BaseService {
3236
has: "TASK_RUN",
3337
},
3438
environmentTypes: {
35-
has: run.runtimeEnvironment.type,
39+
has: run.runtimeEnvironment.parentEnvironment?.type ?? run.runtimeEnvironment.type,
3640
},
3741
enabled: true,
3842
},

internal-packages/emails/emails/alert-run-failure.tsx

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ export const AlertRunEmailSchema = z.object({
2121
project: z.string(),
2222
taskIdentifier: z.string(),
2323
fileName: z.string(),
24-
exportName: z.string(),
2524
version: z.string(),
2625
environment: z.string(),
2726
error: z.object({
@@ -41,7 +40,6 @@ const previewDefaults: AlertRunEmailProps = {
4140
project: "my-project",
4241
taskIdentifier: "my-task",
4342
fileName: "other.ts",
44-
exportName: "myTask",
4543
version: "20240101.1",
4644
environment: "prod",
4745
error: {
@@ -59,7 +57,6 @@ export default function Email(props: AlertRunEmailProps) {
5957
project,
6058
taskIdentifier,
6159
fileName,
62-
exportName,
6360
version,
6461
environment,
6562
error,
@@ -81,7 +78,6 @@ export default function Email(props: AlertRunEmailProps) {
8178
<Text style={paragraphTight}>Project: {project}</Text>
8279
<Text style={paragraphTight}>Task ID: {taskIdentifier}</Text>
8380
<Text style={paragraphTight}>Filename: {fileName}</Text>
84-
<Text style={paragraphTight}>Function: {exportName}()</Text>
8581
<Text style={paragraphTight}>Version: {version}</Text>
8682
<Text style={paragraphTight}>Environment: {environment}</Text>
8783

packages/core/src/v3/schemas/webhooks.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,8 @@ const AlertWebhookRunFailedObject = z.object({
5656
type: RuntimeEnvironmentTypeSchema,
5757
/** Environment slug */
5858
slug: z.string(),
59+
/** Environment branch name */
60+
branchName: z.string().optional(),
5961
}),
6062
/** Organization information */
6163
organization: z.object({
@@ -99,6 +101,8 @@ const deploymentCommonProperties = {
99101
id: z.string(),
100102
type: RuntimeEnvironmentTypeSchema,
101103
slug: z.string(),
104+
/** Environment branch name */
105+
branchName: z.string().optional(),
102106
}),
103107
/** Organization information */
104108
organization: z.object({

0 commit comments

Comments
 (0)