Skip to content

fix(webhooks): normalize watch path changed-file matching#4085

Open
jakvbs wants to merge 2 commits intoDokploy:canaryfrom
jakvbs:fix/watch-path-webhook-crash
Open

fix(webhooks): normalize watch path changed-file matching#4085
jakvbs wants to merge 2 commits intoDokploy:canaryfrom
jakvbs:fix/watch-path-webhook-crash

Conversation

@jakvbs
Copy link
Copy Markdown

@jakvbs jakvbs commented Mar 28, 2026

What is this PR about?

This PR fixes a crash in Dokploy webhook-driven auto-deploys when Watch Paths are enabled and the incoming webhook payload contains missing or partial changed-file arrays. It makes watch path evaluation defensive against nullish file lists and normalizes changed files across added, modified, and removed entries before matching.

Checklist

Before submitting this PR, please make sure that:

  • You created a dedicated branch based on the canary branch.
  • You have read the suggestions in the CONTRIBUTING.md file https://github.com/Dokploy/dokploy/blob/canary/CONTRIBUTING.md#pull-request
  • You have tested this PR in your local instance. If you have not tested it yet, please do so before submitting. This helps avoid wasting maintainers' time reviewing code that has not been verified by you.

Issues related (if applicable)

Closes #4081

Screenshots (if applicable)

N/A

Additional notes

What changed

  • make shouldDeploy() return false instead of throwing when the changed-file list is missing or contains only nullish values
  • add normalizeChangedFilesFromCommits() to merge added, modified, and removed paths and filter invalid entries
  • update the GitHub, GitLab, and Compose webhook handlers to use the normalized changed-file list
  • add regression tests covering nullish inputs and mixed webhook payload shapes

How this was tested

  • pnpm install
  • cp apps/dokploy/.env.example apps/dokploy/.env
  • pnpm run dokploy:setup
  • pnpm run server:script
  • pnpm run dokploy:dev
  • verified local app startup on http://127.0.0.1:3000 with redirect to /register
  • pnpm exec vitest run __test__/deploy/watch-paths.test.ts __test__/deploy/normalize-changed-files.test.ts --config __test__/vitest.config.ts

Environment note

  • tested locally on macOS with Node 24.4.0
  • native module install required explicit SDK environment variables for the local machine toolchain:
    • SDKROOT=$(xcrun --show-sdk-path)
    • CPLUS_INCLUDE_PATH=/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/c++/v1

Greptile Summary

This PR fixes a crash in Dokploy's webhook-driven auto-deploy when Watch Paths are configured and the incoming payload contains a missing or partial commits array. It introduces normalizeChangedFilesFromCommits() to safely merge added, modified, and removed file paths from each commit while filtering out null/undefined/empty entries, updates shouldDeploy() to be null-safe (returning false instead of crashing on missing file lists), and applies both changes across all webhook handlers (GitHub, GitLab, Gitea, soft-serve, and Compose variants).

Key changes:

  • New normalizeChangedFilesFromCommits() utility in packages/server/src/utils/watch-paths/normalize-changed-files.ts that defensively aggregates all three file-change buckets per commit
  • shouldDeploy() updated to accept null | undefined input and return false for empty normalized file lists instead of passing undefined to micromatch.some()
  • All webhook handler call-sites migrated from the crash-prone flatMap((c) => c.modified) pattern to the new utility — this also broadens watch-path matching to include added and removed files (intentional, correct behavior)
  • Regression tests covering nullish inputs, mixed payloads, and empty-commit edge cases

Confidence Score: 5/5

Safe to merge — the fix is narrowly scoped, well-tested, and only changes crash behavior to a safe default of skipping the deploy.

All changes are defensive null-safety improvements with no logic regressions. The only semantic change beyond the crash fix (now including added/removed files in watch-path matching) is intentional, documented, and correct. Tests cover the key regression scenarios.

No files require special attention.

Important Files Changed

Filename Overview
packages/server/src/utils/watch-paths/normalize-changed-files.ts New utility that cleanly merges added/modified/removed paths from commit payloads, filtering all nullish and empty-string values. Implementation is correct and the CommitLike interface is appropriately typed.
packages/server/src/utils/watch-paths/should-deploy.ts Updated to accept null/undefined modifiedFiles input, returning false instead of crashing when the normalized file list is empty.
apps/dokploy/pages/api/deploy/[refreshToken].ts All flatMap commit.modified call-sites replaced with normalizeChangedFilesFromCommits across github, gitlab, gitea, and soft-serve providers.
apps/dokploy/pages/api/deploy/compose/[refreshToken].ts Same migration applied to Compose webhook handler for github, gitlab, and gitea providers.
apps/dokploy/pages/api/deploy/github.ts GitHub-specific webhook handler updated to use normalizeChangedFilesFromCommits.
apps/dokploy/test/deploy/normalize-changed-files.test.ts New regression tests covering merged file arrays, nullish/empty filtering, and empty commit input.
apps/dokploy/test/deploy/watch-paths.test.ts New regression tests covering shouldDeploy behavior with undefined, nullish-only, and mixed file arrays.

Reviews (1): Last reviewed commit: "fix(webhooks): normalize changed file pa..." | Re-trigger Greptile

(5/5) You can turn off certain types of comments like style here!

@jakvbs jakvbs requested a review from Siumauricio as a code owner March 28, 2026 19:48
@dosubot dosubot bot added size:L This PR changes 100-499 lines, ignoring generated files. bug Something isn't working labels Mar 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working size:L This PR changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Compose GitHub auto-deploy webhook crashes when Watch Paths are enabled and commits have missing modified entries

1 participant