Skip to content

Commit c523b35

Browse files
committed
Increase the tags limit to 5, do the limiting on the server
1 parent 6714a3c commit c523b35

File tree

4 files changed

+18
-9
lines changed

4 files changed

+18
-9
lines changed

apps/webapp/app/models/taskRunTag.server.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import { prisma } from "~/db.server";
22
import { generateFriendlyId } from "~/v3/friendlyIdentifiers";
33

4+
export const MAX_TAGS_PER_RUN = 5;
5+
46
export async function createTag({ tag, projectId }: { tag: string; projectId: string }) {
57
if (tag.trim().length === 0) return;
68
return prisma.taskRunTag.upsert({

apps/webapp/app/routes/api.v1.runs.$runId.tags.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { type ActionFunctionArgs, json } from "@remix-run/server-runtime";
22
import { AddTagsRequestBody } from "@trigger.dev/core/v3";
33
import { z } from "zod";
44
import { prisma } from "~/db.server";
5-
import { createTag, getTagsForRunId } from "~/models/taskRunTag.server";
5+
import { createTag, getTagsForRunId, MAX_TAGS_PER_RUN } from "~/models/taskRunTag.server";
66
import { authenticateApiRequest } from "~/services/apiAuth.server";
77
import { generateFriendlyId } from "~/v3/friendlyIdentifiers";
88

@@ -51,12 +51,12 @@ export async function action({ request, params }: ActionFunctionArgs) {
5151
return !existingTags.map((t) => t.name).includes(tag);
5252
});
5353

54-
if (existingTags.length + newTags.length > 3) {
54+
if (existingTags.length + newTags.length > MAX_TAGS_PER_RUN) {
5555
return json(
5656
{
57-
error: `Runs can only have 3 tags, you're trying to set ${
57+
error: `Runs can only have ${MAX_TAGS_PER_RUN} tags, you're trying to set ${
5858
existingTags.length + newTags.length
59-
}.`,
59+
}. These tags have not been set: ${newTags.map((t) => `'${t}'`).join(", ")}.`,
6060
},
6161
{ status: 422 }
6262
);

apps/webapp/app/v3/services/triggerTask.server.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import { getEntitlement } from "~/services/platform.v3.server";
1717
import { BaseService, ServiceValidationError } from "./baseService.server";
1818
import { logger } from "~/services/logger.server";
1919
import { isFinalAttemptStatus, isFinalRunStatus } from "../taskStatus";
20-
import { createTag } from "~/models/taskRunTag.server";
20+
import { createTag, MAX_TAGS_PER_RUN } from "~/models/taskRunTag.server";
2121

2222
export type TriggerTaskServiceOptions = {
2323
idempotencyKey?: string;
@@ -78,6 +78,16 @@ export class TriggerTaskService extends BaseService {
7878
}
7979
}
8080

81+
if (
82+
body.options?.tags &&
83+
typeof body.options.tags !== "string" &&
84+
body.options.tags.length > MAX_TAGS_PER_RUN
85+
) {
86+
throw new ServiceValidationError(
87+
`Runs can only have ${MAX_TAGS_PER_RUN} tags, you're trying to set ${body.options.tags.length}.`
88+
);
89+
}
90+
8191
const runFriendlyId = generateFriendlyId("run");
8292

8393
const payloadPacket = await this.#handlePayloadPacket(

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

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,10 +57,7 @@ export type CreateBackgroundWorkerResponse = z.infer<typeof CreateBackgroundWork
5757

5858
//an array of 1, 2, or 3 strings
5959
const RunTag = z.string().max(64, "Tags must be less than 64 characters");
60-
export const RunTags = z.union([
61-
RunTag,
62-
RunTag.array().max(3, "You can only set a maximum of 3 tags on a run."),
63-
]);
60+
export const RunTags = z.union([RunTag, RunTag.array()]);
6461

6562
export type RunTags = z.infer<typeof RunTags>;
6663

0 commit comments

Comments
 (0)