From bcf97f92aba99406b5c4471962ce23b82fba18ca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Narciso=20E=2E=20N=C3=BA=C3=B1ez=20Arias?= Date: Wed, 5 Aug 2026 22:21:12 -0400 Subject: [PATCH] Merge pull request #4772 from rifatdinc/fix-watch-paths-added-removed-files fix(webhook): include added and removed files in watchPaths validation (cherry picked from commit 3f98208f03072bf076a36b0c495c386142aab31b) --- .../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(