From ca1fa7c4f7a61013ad6d011002028df69a5616cb Mon Sep 17 00:00:00 2001 From: Mauricio Siu <47042324+Siumauricio@users.noreply.github.com> Date: Sat, 23 Aug 2025 20:11:18 -0600 Subject: [PATCH] feat: add support for preview labels in deployment process --- apps/dokploy/pages/api/deploy/github.ts | 22 +++++++++++--------- packages/server/src/db/schema/application.ts | 1 + 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/apps/dokploy/pages/api/deploy/github.ts b/apps/dokploy/pages/api/deploy/github.ts index 7e3df5444..92cf3dc9e 100644 --- a/apps/dokploy/pages/api/deploy/github.ts +++ b/apps/dokploy/pages/api/deploy/github.ts @@ -1,22 +1,22 @@ -import { db } from "@/server/db"; -import { applications, compose, github } from "@/server/db/schema"; -import type { DeploymentJob } from "@/server/queues/queue-types"; -import { myQueue } from "@/server/queues/queueSetup"; -import { deploy } from "@/server/utils/deploy"; import { - IS_CLOUD, checkUserRepositoryPermissions, createPreviewDeployment, createSecurityBlockedComment, findGithubById, findPreviewDeploymentByApplicationId, findPreviewDeploymentsByPullRequestId, + IS_CLOUD, removePreviewDeployment, shouldDeploy, } from "@dokploy/server"; import { Webhooks } from "@octokit/webhooks"; import { and, eq } from "drizzle-orm"; import type { NextApiRequest, NextApiResponse } from "next"; +import { db } from "@/server/db"; +import { applications, compose, github } from "@/server/db/schema"; +import type { DeploymentJob } from "@/server/queues/queue-types"; +import { myQueue } from "@/server/queues/queueSetup"; +import { deploy } from "@/server/utils/deploy"; import { extractCommitMessage, extractHash } from "./[refreshToken]"; export default async function handler( @@ -343,7 +343,9 @@ export default async function handler( if ( action === "opened" || action === "synchronize" || - action === "reopened" + action === "reopened" || + action === "labeled" || + action === "unlabeled" ) { const repository = githubBody?.repository?.name; const deploymentHash = githubBody?.pull_request?.head?.sha; @@ -443,11 +445,11 @@ export default async function handler( for (const app of secureApps) { // check for labels - if (app?.previewLabels.size() > 0) { - let hasLabel: boolean = false; + if (app?.previewLabels && app?.previewLabels?.length > 0) { + let hasLabel = false; const labels = githubBody?.pull_request?.labels; for (const label of labels) { - if (app?.previewLabels.contains(label.name)) { + if (app?.previewLabels?.includes(label.name)) { hasLabel = true; break; } diff --git a/packages/server/src/db/schema/application.ts b/packages/server/src/db/schema/application.ts index 21ee9fbda..198611a77 100644 --- a/packages/server/src/db/schema/application.ts +++ b/packages/server/src/db/schema/application.ts @@ -309,6 +309,7 @@ const createSchema = createInsertSchema(applications, { previewCertificateType: z.enum(["letsencrypt", "none", "custom"]).optional(), previewRequireCollaboratorPermissions: z.boolean().optional(), watchPaths: z.array(z.string()).optional(), + previewLabels: z.array(z.string()).optional(), cleanCache: z.boolean().optional(), });