feat(workflow): support nested dot-notation in webhook trigger fields (#4235) - #4262
Open
iroiro147 wants to merge 1 commit into
Open
feat(workflow): support nested dot-notation in webhook trigger fields (#4235)#4262iroiro147 wants to merge 1 commit into
iroiro147 wants to merge 1 commit into
Conversation
…block#4235) Webhook-triggered workflows previously received only top-level JSON fields — nested objects were stringified whole into a single value, making `{{trigger.data.title}}` unusable when the sender posted CloudEvents-style envelopes: {"type":"workflow.failed","data":{"title":"Deploy","reason":"Timeout"}} The fix introduces `flatten_webhook_fields` in buzz-workflow (executor.rs): a shared helper that recursively flattens nested JSON objects and arrays into dot-notation keys (`data.title`, `items.0.nested`, etc.). Scalar values are stringified; objects/arrays are kept at their prefix as serialized JSON so existing templates like `{{trigger.data}}` still resolve to the raw JSON for consumers who want the whole envelope. Both webhook-population sites now use the shared helper: - crates/buzz-relay/src/api/bridge.rs:1889 — HTTP `/workflows/{id}/webhook` - crates/buzz-relay/src/handlers/command_executor.rs:919 — message_posted triggers parsing event.content as JSON Behavior change: - `{{trigger.data.title}}` → `"Deploy"` (was: literal template text) - `{{trigger.data}}` → serialized JSON string (unchanged) - `{{trigger.data.meta.attempt}}` → nested-scalar lookup (new) - Array indexing: `{{trigger.items.0.name}}` (new) Existing top-level fields preserved verbatim — no consumer should observe a breaking change. Regression tests in buzz-workflow (executor.rs): - flatten_nested_object_produces_dotted_keys - flatten_scalar_types_convert_to_strings - flatten_array_produces_indexed_dotted_keys - resolve_template_uses_nested_webhook_field (end-to-end template substitution over flattened context) Verified: - `cargo test -p buzz-workflow --lib` — 157 passed, 0 failed - `cargo test -p buzz-relay --lib bridge` — 59 passed, 0 failed - `cargo check -p buzz-workflow -p buzz-relay` — clean Refs block#4235 Signed-off-by: Sarthak Singh <sarthak.singh@juspay.in>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Webhook-triggered workflows received only top-level JSON fields because nested objects were stringified into a single value. A CloudEvents-style body like
{"type":"workflow.failed","data":{"title":"Deploy","reason":"Timeout"}}surfaced
{{trigger.type}}→"workflow.failed"but{{trigger.data.title}}was unreachable —dataitself was the entire serialized JSON, unusable as a sub-template key. Senders had to duplicate useful fields at the top level just for Buzz.Both webhook-population sites had the same flat-stringify pattern (bridge.rs /workflows HTTP endpoint, command_executor.rs message_posted trigger with JSON content). This PR introduces a shared
flatten_webhook_fieldshelper inbuzz-workflow::executorthat recursively flattens nested JSON objects/arrays into dot-notation keys, and swaps both call sites to use it.Behavior
{{trigger.data.title}}"Deploy"{{trigger.data}}{{trigger.data.meta.attempt}}"3"{{trigger.items.0.name}}{{trigger.count}}(top-level scalar)"42""42"(unchanged)Objects and arrays are still stored under their prefix as serialized JSON, so consumers who want the whole envelope continue to work. Existing top-level templates are bit-for-bit identical.
Implementation
One new shared function
flatten_webhook_fields(map: &serde_json::Map<String, serde_json::Value>) -> HashMap<String, String>incrates/buzz-workflow/src/executor.rs:data.title,items.0.nestedBoth former inline loops replaced with one call:
bridge.rs:1889(HTTP/workflows/{id}/webhook)command_executor.rs:919(message_posted trigger parsingevent.contentas JSON)Tests
Four new unit tests in
crates/buzz-workflow/src/executor.rs:flatten_nested_object_produces_dotted_keys— CloudEvents-style shapeflatten_scalar_types_convert_to_strings—number/bool/nullflatten_array_produces_indexed_dotted_keys—items.0etc.resolve_template_uses_nested_webhook_field— end-to-end substitutioncargo test -p buzz-workflow --lib— 157 passed, 0 failed (4 new + 153 existing).cargo test -p buzz-relay --lib bridge— 59 passed, 0 failed.cargo check -p buzz-workflow -p buzz-relay— clean.Linked issue
Refs #4235