buzz
buzz copied to clipboard
feat(workflow): add json() template filter for webhook payload extraction
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
nullresolve 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