From 2df02f596afe6cd8e9cd4c015d2393cea709a252 Mon Sep 17 00:00:00 2001 From: Antigravity AI Date: Thu, 9 Jul 2026 00:06:10 +0300 Subject: [PATCH] fix(webhook): include added and removed files in watchPaths validation Currently, Dokploy only extracts modified files from webhook payloads. This causes watchPaths to fail matching commits that only add or remove files (such as adding new routes or deleting files), preventing auto-deployments. This commit updates the commit parsing logic to aggregate added, modified, and removed files. --- .../pages/api/deploy/[refreshToken].ts | 56 ++++++++++++------- .../api/deploy/compose/[refreshToken].ts | 48 ++++++++++------ apps/dokploy/pages/api/deploy/github.ts | 8 ++- 3 files changed, 70 insertions(+), 42 deletions(-) diff --git a/apps/dokploy/pages/api/deploy/[refreshToken].ts b/apps/dokploy/pages/api/deploy/[refreshToken].ts index bb6eb06d3..9cf6142d2 100644 --- a/apps/dokploy/pages/api/deploy/[refreshToken].ts +++ b/apps/dokploy/pages/api/deploy/[refreshToken].ts @@ -119,9 +119,11 @@ export default async function handler( } // If webhook doesn't provide image info, we'll use the configured image (old behavior) } else if (sourceType === "github") { - const normalizedCommits = req.body?.commits?.flatMap( - (commit: any) => commit.modified, - ); + const normalizedCommits = req.body?.commits?.flatMap((commit: any) => [ + ...(commit.added || []), + ...(commit.modified || []), + ...(commit.removed || []), + ]); const shouldDeployPaths = shouldDeploy( application.watchPaths, @@ -150,21 +152,29 @@ export default async function handler( let normalizedCommits: string[] = []; if (provider === "github") { - normalizedCommits = req.body?.commits?.flatMap( - (commit: any) => commit.modified, - ); + normalizedCommits = req.body?.commits?.flatMap((commit: any) => [ + ...(commit.added || []), + ...(commit.modified || []), + ...(commit.removed || []), + ]); } else if (provider === "gitlab") { - normalizedCommits = req.body?.commits?.flatMap( - (commit: any) => commit.modified, - ); + normalizedCommits = req.body?.commits?.flatMap((commit: any) => [ + ...(commit.added || []), + ...(commit.modified || []), + ...(commit.removed || []), + ]); } else if (provider === "gitea") { - normalizedCommits = req.body?.commits?.flatMap( - (commit: any) => commit.modified, - ); + normalizedCommits = req.body?.commits?.flatMap((commit: any) => [ + ...(commit.added || []), + ...(commit.modified || []), + ...(commit.removed || []), + ]); } else if (provider === "soft-serve") { - normalizedCommits = req.body?.commits?.flatMap( - (commit: any) => commit.modified, - ); + normalizedCommits = req.body?.commits?.flatMap((commit: any) => [ + ...(commit.added || []), + ...(commit.modified || []), + ...(commit.removed || []), + ]); } const shouldDeployPaths = shouldDeploy( @@ -179,9 +189,11 @@ export default async function handler( } else if (sourceType === "gitlab") { const branchName = extractBranchName(req.headers, req.body); - const normalizedCommits = req.body?.commits?.flatMap( - (commit: any) => commit.modified, - ); + const normalizedCommits = req.body?.commits?.flatMap((commit: any) => [ + ...(commit.added || []), + ...(commit.modified || []), + ...(commit.removed || []), + ]); const shouldDeployPaths = shouldDeploy( application.watchPaths, @@ -225,9 +237,11 @@ export default async function handler( } else if (sourceType === "gitea") { const branchName = extractBranchName(req.headers, req.body); - const normalizedCommits = req.body?.commits?.flatMap( - (commit: any) => commit.modified, - ); + const normalizedCommits = req.body?.commits?.flatMap((commit: any) => [ + ...(commit.added || []), + ...(commit.modified || []), + ...(commit.removed || []), + ]); const shouldDeployPaths = shouldDeploy( application.watchPaths, diff --git a/apps/dokploy/pages/api/deploy/compose/[refreshToken].ts b/apps/dokploy/pages/api/deploy/compose/[refreshToken].ts index 85a379eb3..0d83c1017 100644 --- a/apps/dokploy/pages/api/deploy/compose/[refreshToken].ts +++ b/apps/dokploy/pages/api/deploy/compose/[refreshToken].ts @@ -54,9 +54,11 @@ export default async function handler( if (sourceType === "github") { const branchName = extractBranchName(req.headers, req.body); - const normalizedCommits = req.body?.commits?.flatMap( - (commit: any) => commit.modified, - ); + const normalizedCommits = req.body?.commits?.flatMap((commit: any) => [ + ...(commit.added || []), + ...(commit.modified || []), + ...(commit.removed || []), + ]); const shouldDeployPaths = shouldDeploy( composeResult.watchPaths, @@ -74,9 +76,11 @@ export default async function handler( } } else if (sourceType === "gitlab") { const branchName = extractBranchName(req.headers, req.body); - const normalizedCommits = req.body?.commits?.flatMap( - (commit: any) => commit.modified, - ); + const normalizedCommits = req.body?.commits?.flatMap((commit: any) => [ + ...(commit.added || []), + ...(commit.modified || []), + ...(commit.removed || []), + ]); const shouldDeployPaths = shouldDeploy( composeResult.watchPaths, @@ -125,17 +129,23 @@ export default async function handler( let normalizedCommits: string[] = []; if (provider === "github") { - normalizedCommits = req.body?.commits?.flatMap( - (commit: any) => commit.modified, - ); + normalizedCommits = req.body?.commits?.flatMap((commit: any) => [ + ...(commit.added || []), + ...(commit.modified || []), + ...(commit.removed || []), + ]); } else if (provider === "gitlab") { - normalizedCommits = req.body?.commits?.flatMap( - (commit: any) => commit.modified, - ); + normalizedCommits = req.body?.commits?.flatMap((commit: any) => [ + ...(commit.added || []), + ...(commit.modified || []), + ...(commit.removed || []), + ]); } else if (provider === "gitea") { - normalizedCommits = req.body?.commits?.flatMap( - (commit: any) => commit.modified, - ); + normalizedCommits = req.body?.commits?.flatMap((commit: any) => [ + ...(commit.added || []), + ...(commit.modified || []), + ...(commit.removed || []), + ]); } const shouldDeployPaths = shouldDeploy( @@ -150,9 +160,11 @@ export default async function handler( } else if (sourceType === "gitea") { const branchName = extractBranchName(req.headers, req.body); - const normalizedCommits = req.body?.commits?.flatMap( - (commit: any) => commit.modified, - ); + const normalizedCommits = req.body?.commits?.flatMap((commit: any) => [ + ...(commit.added || []), + ...(commit.modified || []), + ...(commit.removed || []), + ]); const shouldDeployPaths = shouldDeploy( composeResult.watchPaths, diff --git a/apps/dokploy/pages/api/deploy/github.ts b/apps/dokploy/pages/api/deploy/github.ts index f03bf786e..4fc75fc50 100644 --- a/apps/dokploy/pages/api/deploy/github.ts +++ b/apps/dokploy/pages/api/deploy/github.ts @@ -223,9 +223,11 @@ export default async function handler( const deploymentTitle = extractCommitMessage(req.headers, req.body); const deploymentHash = extractHash(req.headers, req.body); const owner = getGithubRepositoryOwner(githubBody); - const normalizedCommits = githubBody?.commits?.flatMap( - (commit: any) => commit.modified, - ); + const normalizedCommits = githubBody?.commits?.flatMap((commit: any) => [ + ...(commit.added || []), + ...(commit.modified || []), + ...(commit.removed || []), + ]); const apps = await db.query.applications.findMany({ where: and(