From 17b4c0fc583035cedb8f3e52215bf54fb63f9ce8 Mon Sep 17 00:00:00 2001 From: Mauricio Siu Date: Sun, 5 Apr 2026 13:37:44 -0600 Subject: [PATCH] fix: webhook crash when commits array is missing and watch paths enabled When a GitHub webhook fires with undefined commits and watch paths are configured, flatMap on undefined crashes the handler. Default to empty array so shouldDeploy can handle it gracefully. Closes #4081 --- .../api/deploy/compose/[refreshToken].ts | 42 +++++++++++-------- apps/dokploy/pages/api/deploy/github.ts | 7 ++-- 2 files changed, 28 insertions(+), 21 deletions(-) diff --git a/apps/dokploy/pages/api/deploy/compose/[refreshToken].ts b/apps/dokploy/pages/api/deploy/compose/[refreshToken].ts index 640a2531d..e22149f35 100644 --- a/apps/dokploy/pages/api/deploy/compose/[refreshToken].ts +++ b/apps/dokploy/pages/api/deploy/compose/[refreshToken].ts @@ -53,9 +53,10 @@ 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.modified, + ) || []; const shouldDeployPaths = shouldDeploy( composeResult.watchPaths, @@ -73,9 +74,10 @@ 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.modified, + ) || []; const shouldDeployPaths = shouldDeploy( composeResult.watchPaths, @@ -124,17 +126,20 @@ 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.modified, + ) || []; } else if (provider === "gitlab") { - normalizedCommits = req.body?.commits?.flatMap( - (commit: any) => commit.modified, - ); + normalizedCommits = + req.body?.commits?.flatMap( + (commit: any) => commit.modified, + ) || []; } else if (provider === "gitea") { - normalizedCommits = req.body?.commits?.flatMap( - (commit: any) => commit.modified, - ); + normalizedCommits = + req.body?.commits?.flatMap( + (commit: any) => commit.modified, + ) || []; } const shouldDeployPaths = shouldDeploy( @@ -149,9 +154,10 @@ 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.modified, + ) || []; const shouldDeployPaths = shouldDeploy( composeResult.watchPaths, diff --git a/apps/dokploy/pages/api/deploy/github.ts b/apps/dokploy/pages/api/deploy/github.ts index 4438366f6..82106ef2c 100644 --- a/apps/dokploy/pages/api/deploy/github.ts +++ b/apps/dokploy/pages/api/deploy/github.ts @@ -213,9 +213,10 @@ export default async function handler( const deploymentTitle = extractCommitMessage(req.headers, req.body); const deploymentHash = extractHash(req.headers, req.body); const owner = githubBody?.repository?.owner?.name; - const normalizedCommits = githubBody?.commits?.flatMap( - (commit: any) => commit.modified, - ); + const normalizedCommits = + githubBody?.commits?.flatMap( + (commit: any) => commit.modified, + ) || []; const apps = await db.query.applications.findMany({ where: and(