Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .changes/unreleased/Added-20260603-143053.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
kind: Added
body: Added Notifiers field to WebHook and WebHookInput structs to support email notification on circuit breaker events
time: 2026-06-03T14:30:53.347423+01:00
2 changes: 2 additions & 0 deletions management/webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ type WebHook struct {
RetryPolicy string `json:"retry_policy"`
Disabled bool `json:"disabled"`
ConcisePayload bool `json:"concise_payload"`
Notifiers []string `json:"notifiers"`
}

type WebhookDestination struct {
Expand All @@ -53,6 +54,7 @@ type WebHookInput struct {
RetryPolicy string `json:"retry_policy"`
Disabled bool `json:"disabled"`
ConcisePayload bool `json:"concise_payload"`
Notifiers []string `json:"notifiers"`
}

func (si *StackInstance) WebHookCreate(ctx context.Context, input WebHookInput) (*WebHook, error) {
Expand Down
54 changes: 54 additions & 0 deletions management/webhook_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package management

import (
"encoding/json"
"testing"
)

func TestWebHookInput_NotifiersSerializedToJSON(t *testing.T) {
input := WebHookRequest{
WebHook: WebHookInput{
Name: "test-hook",
Notifiers: []string{"ops@example.com", "dev@example.com"},
},
}
data, err := json.Marshal(input)
if err != nil {
t.Fatalf("unexpected marshal error: %v", err)
}
var result map[string]interface{}
if err := json.Unmarshal(data, &result); err != nil {
t.Fatalf("unexpected unmarshal error: %v", err)
}
webhook, ok := result["webhook"].(map[string]interface{})
if !ok {
t.Fatal("expected webhook key in JSON")
}
notifiers, ok := webhook["notifiers"].([]interface{})
if !ok {
t.Fatalf("expected notifiers to be an array, got: %v", webhook["notifiers"])
}
if len(notifiers) != 2 {
t.Errorf("expected 2 notifiers, got %d", len(notifiers))
}
if notifiers[0].(string) != "ops@example.com" {
t.Errorf("expected ops@example.com, got %s", notifiers[0])
}
if notifiers[1].(string) != "dev@example.com" {
t.Errorf("expected dev@example.com, got %s", notifiers[1])
}
}

func TestWebHook_NotifiersDeserializedFromJSON(t *testing.T) {
raw := `{"webhook":{"name":"test","notifiers":["ops@example.com"]}}`
var result WebHookResponse
if err := json.Unmarshal([]byte(raw), &result); err != nil {
t.Fatalf("unexpected unmarshal error: %v", err)
}
if len(result.WebHook.Notifiers) != 1 {
t.Errorf("expected 1 notifier, got %d", len(result.WebHook.Notifiers))
}
if result.WebHook.Notifiers[0] != "ops@example.com" {
t.Errorf("expected ops@example.com, got %s", result.WebHook.Notifiers[0])
}
}
Loading