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
This commit is contained in:
Mauricio Siu
2026-04-05 13:37:44 -06:00
parent 4077af1308
commit 17b4c0fc58
2 changed files with 28 additions and 21 deletions

View File

@@ -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,

View File

@@ -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(