feat: add support for preview labels in deployment process

This commit is contained in:
Mauricio Siu
2025-08-23 20:11:18 -06:00
parent 15e62961e8
commit ca1fa7c4f7
2 changed files with 13 additions and 10 deletions

View File

@@ -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;
}

View File

@@ -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(),
});