From 459c94929a893d44cd6170b019e6119bd98dc62d Mon Sep 17 00:00:00 2001 From: Theo D Date: Mon, 21 Apr 2025 02:25:41 +0200 Subject: [PATCH] fix GitHub event handling for tag deployments. --- ...igger_type.sql => 0085_add_trigger_type.sql} | 0 apps/dokploy/pages/api/deploy/github.ts | 17 ++++++++--------- 2 files changed, 8 insertions(+), 9 deletions(-) rename apps/dokploy/drizzle/{0084_add_trigger_type.sql => 0085_add_trigger_type.sql} (100%) diff --git a/apps/dokploy/drizzle/0084_add_trigger_type.sql b/apps/dokploy/drizzle/0085_add_trigger_type.sql similarity index 100% rename from apps/dokploy/drizzle/0084_add_trigger_type.sql rename to apps/dokploy/drizzle/0085_add_trigger_type.sql diff --git a/apps/dokploy/pages/api/deploy/github.ts b/apps/dokploy/pages/api/deploy/github.ts index 4757bbab5..15547d723 100644 --- a/apps/dokploy/pages/api/deploy/github.ts +++ b/apps/dokploy/pages/api/deploy/github.ts @@ -62,12 +62,11 @@ export default async function handler( if ( req.headers["x-github-event"] !== "push" && - req.headers["x-github-event"] !== "pull_request" && - req.headers["x-github-event"] !== "create" + req.headers["x-github-event"] !== "pull_request" ) { res .status(400) - .json({ message: "We only accept push, pull_request, or create events" }); + .json({ message: "We only accept push events or pull_request events" }); return; } @@ -92,17 +91,17 @@ export default async function handler( // Handle tag creation event if ( - req.headers["x-github-event"] === "create" && - githubBody?.ref_type === "tag" + req.headers["x-github-event"] === "push" && + githubBody?.ref?.startsWith("refs/tags/") ) { try { - const tagName = githubBody?.ref; + const tagName = githubBody?.ref.replace("refs/tags/", ""); const repository = githubBody?.repository?.name; const owner = githubBody?.repository?.owner?.name || githubBody?.repository?.owner?.login; const deploymentTitle = `Tag created: ${tagName}`; - const deploymentHash = githubBody?.master_branch || ""; + const deploymentHash = extractHash(req.headers, githubBody); // Find applications configured to deploy on tag const apps = await db.query.applications.findMany({ @@ -120,7 +119,7 @@ export default async function handler( const jobData: DeploymentJob = { applicationId: app.applicationId as string, titleLog: deploymentTitle, - descriptionLog: `Tag: ${tagName}`, + descriptionLog: `Hash: ${deploymentHash}`, type: "deploy", applicationType: "application", server: !!app.serverId, @@ -159,7 +158,7 @@ export default async function handler( titleLog: deploymentTitle, type: "deploy", applicationType: "compose", - descriptionLog: `Tag: ${tagName}`, + descriptionLog: `Hash: ${deploymentHash}`, server: !!composeApp.serverId, };