Preview branch alerts (#2136)
* Preview branch alerts * Show “Preview” not the branch for new alert modal
This commit is contained in:
+3
-3
@@ -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() {
|
||||
<InputGroup>
|
||||
<Label>Environment</Label>
|
||||
<input type="hidden" name={environmentTypes.name} value={environment.type} />
|
||||
<EnvironmentCombo environment={environment} />
|
||||
<EnvironmentCombo environment={{ type: environment.type }} />
|
||||
<FormError id={environmentTypes.errorId}>{environmentTypes.error}</FormError>
|
||||
</InputGroup>
|
||||
<FormError>{form.error}</FormError>
|
||||
|
||||
@@ -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}* _<!date^${Math.round(
|
||||
text: `:rotating_light: Error in *${taskIdentifier}* _<!date^${Math.round(
|
||||
timestamp.getTime() / 1000
|
||||
)}^at {date_num} {time_secs}|${timestamp.toLocaleString()}>_`,
|
||||
},
|
||||
|
||||
@@ -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,
|
||||
},
|
||||
|
||||
@@ -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) {
|
||||
<Text style={paragraphTight}>Project: {project}</Text>
|
||||
<Text style={paragraphTight}>Task ID: {taskIdentifier}</Text>
|
||||
<Text style={paragraphTight}>Filename: {fileName}</Text>
|
||||
<Text style={paragraphTight}>Function: {exportName}()</Text>
|
||||
<Text style={paragraphTight}>Version: {version}</Text>
|
||||
<Text style={paragraphTight}>Environment: {environment}</Text>
|
||||
|
||||
|
||||
@@ -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({
|
||||
|
||||
Reference in New Issue
Block a user