Skip to content

Commit b06138b

Browse files
authored
fix: prevent webhook deploy crash when commit data lacks modified files (Dokploy#4470)
shouldDeploy passed undefined/null entries from commit.modified straight into micromatch, which throws "Expected input to be a string" and fails every webhook deployment when watch paths are configured. Filter out non-string values before matching.
1 parent af8072d commit b06138b

2 files changed

Lines changed: 46 additions & 2 deletions

File tree

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import { shouldDeploy } from "@dokploy/server";
2+
import { describe, expect, it } from "vitest";
3+
4+
describe("shouldDeploy", () => {
5+
it("should deploy when no watch paths are configured", () => {
6+
expect(shouldDeploy(null, ["src/index.ts"])).toBe(true);
7+
expect(shouldDeploy([], ["src/index.ts"])).toBe(true);
8+
});
9+
10+
it("should deploy when watch paths match modified files", () => {
11+
expect(shouldDeploy(["src/**"], ["src/index.ts"])).toBe(true);
12+
expect(shouldDeploy(["apps/web/**"], ["apps/web/page.tsx"])).toBe(true);
13+
});
14+
15+
it("should not deploy when watch paths do not match", () => {
16+
expect(shouldDeploy(["src/**"], ["docs/readme.md"])).toBe(false);
17+
});
18+
19+
it("should not throw when modified files contain non-string values", () => {
20+
expect(() =>
21+
shouldDeploy(["src/**"], ["src/index.ts", undefined, null] as any),
22+
).not.toThrow();
23+
expect(
24+
shouldDeploy(["src/**"], ["src/index.ts", undefined, null] as any),
25+
).toBe(true);
26+
});
27+
28+
it("should not throw when modified files are undefined or null", () => {
29+
expect(() => shouldDeploy(["src/**"], undefined)).not.toThrow();
30+
expect(() => shouldDeploy(["src/**"], null)).not.toThrow();
31+
expect(shouldDeploy(["src/**"], undefined)).toBe(false);
32+
expect(shouldDeploy(["src/**"], null)).toBe(false);
33+
});
34+
35+
it("should not throw when every modified file is non-string", () => {
36+
expect(() =>
37+
shouldDeploy(["src/**"], [undefined, undefined] as any),
38+
).not.toThrow();
39+
expect(shouldDeploy(["src/**"], [undefined, undefined] as any)).toBe(false);
40+
});
41+
});

‎packages/server/src/utils/watch-paths/should-deploy.ts‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,11 @@ import micromatch from "micromatch";
22

33
export const shouldDeploy = (
44
watchPaths: string[] | null,
5-
modifiedFiles: string[],
5+
modifiedFiles: (string | null | undefined)[] | null | undefined,
66
): boolean => {
77
if (!watchPaths || watchPaths?.length === 0) return true;
8-
return micromatch.some(modifiedFiles, watchPaths);
8+
const files = (modifiedFiles ?? []).filter(
9+
(file): file is string => typeof file === "string",
10+
);
11+
return micromatch.some(files, watchPaths);
912
};

0 commit comments

Comments
 (0)