feat(executor): implement template interpolation #185

Merged
fuzzy merged 2 commits from feature/implement-template-interpolation into main 2026-07-06 08:22:35 +00:00
Owner

What

Implement command template interpolation in internal/executor/template.go:

  • Interpolate() renders Go text/template commands with webhook payload as context (#65, #66)
  • Template functions (#67):
    • {{ json .field }} — JSON-marshals a value
    • {{ timestamp }} — RFC3339 UTC timestamp
    • {{ quote .field }} — shell-safe single-quoted string
  • Shell metacharacter escaping via quote function (#68)
  • Invalid templates return parse errors
  • Missing fields render as <no value> (Go default)

Why

Commands in config need to reference webhook payload data dynamically. Template interpolation bridges the parsed payload and the shell command to be executed.

Testing

  • Unit tests pass — 7 tests: basic, json, timestamp, quote, quote-with-single-quote, invalid template, missing field
  • Integration tests pass — N/A
  • Manual testing performed — go test ./... and pre-commit pass
  • New tests added for new functionality — template_test.go

Breaking Changes

None.

Notes

  • quote escapes internal single quotes using '\'' pattern
  • Templates use dot-notation for nested fields (e.g., {{ .repository.full_name }})
  • Timestamps are always UTC

Closes #69
Closes #65
Closes #66
Closes #67
Closes #68

## What Implement command template interpolation in `internal/executor/template.go`: - `Interpolate()` renders Go `text/template` commands with webhook payload as context (#65, #66) - Template functions (#67): - `{{ json .field }}` — JSON-marshals a value - `{{ timestamp }}` — RFC3339 UTC timestamp - `{{ quote .field }}` — shell-safe single-quoted string - Shell metacharacter escaping via `quote` function (#68) - Invalid templates return parse errors - Missing fields render as `<no value>` (Go default) ## Why Commands in config need to reference webhook payload data dynamically. Template interpolation bridges the parsed payload and the shell command to be executed. ## Testing - [x] Unit tests pass — 7 tests: basic, json, timestamp, quote, quote-with-single-quote, invalid template, missing field - [ ] Integration tests pass — N/A - [x] Manual testing performed — `go test ./...` and pre-commit pass - [x] New tests added for new functionality — `template_test.go` ## Breaking Changes None. ## Notes - `quote` escapes internal single quotes using `'\''` pattern - Templates use dot-notation for nested fields (e.g., `{{ .repository.full_name }}`) - Timestamps are always UTC Closes #69 Closes #65 Closes #66 Closes #67 Closes #68
Add Interpolate() using Go text/template with:
- Entire payload passed as template data context
- json template function for marshaling values
- timestamp template function (UTC RFC3339)
- quote template function for shell-safe single quoting
- Shell metacharacter escaping via quote function

Closes #65
Closes #66
Closes #67
Closes #68
docs: mark Implement template interpolation tasks as complete
All checks were successful
CI / Pre-commit Hooks (pull_request) Successful in 2m30s
CI / Lint (golangci-lint) (pull_request) Successful in 1m27s
CI / Test (pull_request) Successful in 1m20s
CI / Pre-commit Hooks (push) Successful in 2m28s
CI / Lint (golangci-lint) (push) Successful in 1m27s
CI / Test (push) Successful in 1m21s
4d7e0b1a0d
Closes #69
fuzzy scheduled this pull request to auto merge when all checks succeed 2026-07-06 08:17:46 +00:00
the.auditor left a comment

Review

Clean template interpolation implementation. Lint, vet, all 7 tests pass.

Design highlights:

  • text/template with 3 custom functions: json, timestamp, quote
  • quote uses POSIX-correct single-quote escaping ('o'\''brien' pattern) — prevents shell injection
  • json handles any value via interface{} — works with nested maps, strings, numbers
  • timestamp returns RFC3339 UTC — no arguments, deterministic
  • Parse and execute errors wrapped with context

Tests: 7 tests covering basic interpolation, all 3 functions, quoting edge case with embedded single quote, invalid template (parse error), and missing field placeholder.

No blocking issues.

APPROVED

## Review Clean template interpolation implementation. Lint, vet, all 7 tests pass. **Design highlights**: - `text/template` with 3 custom functions: `json`, `timestamp`, `quote` - `quote` uses POSIX-correct single-quote escaping (`'o'\''brien'` pattern) — prevents shell injection - `json` handles any value via `interface{}` — works with nested maps, strings, numbers - `timestamp` returns RFC3339 UTC — no arguments, deterministic - Parse and execute errors wrapped with context **Tests**: 7 tests covering basic interpolation, all 3 functions, quoting edge case with embedded single quote, invalid template (parse error), and missing field placeholder. **No blocking issues.** **APPROVED**
fuzzy self-assigned this 2026-07-06 08:21:34 +00:00
fuzzy merged commit 4d7e0b1a0d into main 2026-07-06 08:22:35 +00:00
fuzzy deleted branch feature/implement-template-interpolation 2026-07-06 08:22:35 +00:00
Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
2 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
thwap/ttheart!185
No description provided.