Skip to content

feat(workflow): add json() template filter for webhook payload extraction - #2887

Open
genesis1tech wants to merge 1 commit into
block:mainfrom
Genesis-1-Technologies:minor/wf-json-filter
Open

feat(workflow): add json() template filter for webhook payload extraction#2887
genesis1tech wants to merge 1 commit into
block:mainfrom
Genesis-1-Technologies:minor/wf-json-filter

Conversation

@genesis1tech

Copy link
Copy Markdown

Problem

The webhook bridge flattens only top-level payload keys — nested objects arrive as one stringified blob (crates/buzz-relay/src/bridge.rs). So a GitHub issues webhook gives a template exactly one handle, {{trigger.issue}}, and the only filters available were truncate() and npub. A workflow that wants the issue title and body has to dump the entire JSON object into the message.

Change

Adds a json(PATH) filter to apply_filter:

text: |
  New issue #{{trigger.issue | json(number)}}: {{trigger.issue | json(title)}}
  by {{trigger.issue | json(user.login)}}

  {{trigger.issue | json(body)}}
  • Parses the value as JSON, then walks a dot-separated path. Numeric segments index arrays (json(labels.0.name)).
  • String results render unquoted; other scalars render as JSON (41, true).
  • Missing fields and null resolve to an empty string — payload shapes vary across providers and event types, so an absent optional field shouldn't fail the run.
  • A value that isn't JSON at all is a TemplateError: that means the template targets the wrong field, and failing loudly is right.

No new dependencies (serde_json is already in the crate).

Test plan

Six unit tests in executor.rs covering string extraction, non-string scalars, nested paths, array indexing, missing/null → empty, non-JSON value error, and empty path error.

cargo test -p buzz-workflow     # 155 passed, 1 ignored
cargo clippy -p buzz-workflow --all-targets   # clean
cargo fmt -p buzz-workflow --check             # clean

…tion

Webhook payloads stringify nested objects whole, so templates could not
reach fields inside them — a GitHub issues hook renders as one JSON blob.
Add a json(PATH) filter that parses the value and walks a dot-separated
path (json(body), json(user.login), json(labels.0.name)). Missing fields
resolve to an empty string since payload shapes vary across providers;
a non-JSON value is a template error. String results render unquoted.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Signed-off-by: Genesis 1 Technologies LLC <146556214+genesis1tech@users.noreply.github.com>
@genesis1tech
genesis1tech requested a review from a team as a code owner July 25, 2026 20:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant