notifier

package
v0.12.14 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 17, 2026 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Register

func Register(name string, factory Factory)

Register adds a new notifier factory to the registry.

func ResolveTemplate

func ResolveTemplate(tmplStr string, n Notification) string

ResolveTemplate renders a Go template string with notification data. Provides {{.PayloadField "key.path"}} for accessing raw webhook JSON.

Types

type ChannelMetrics

type ChannelMetrics struct {
	Sent    atomic.Int64
	Failed  atomic.Int64
	Retried atomic.Int64
}

ChannelMetrics holds counters for a single notifier channel.

type Config

type Config struct {
	Enabled  []string                          `yaml:"enabled"`
	Settings map[string]map[string]interface{} `yaml:"settings"`
}

Config holds the configuration for all supported notifiers.

func (Config) Validate

func (c Config) Validate() []error

Validate checks that all enabled notifiers have valid configuration. Returns errors for each misconfigured notifier without creating them.

type DiscordBotNotifier

type DiscordBotNotifier struct {
	GuildID         string
	CategoryID      string
	ChannelID       string
	NotifyChannelID string // dedicated channel ID to route all notifications to
	// contains filtered or unexported fields
}

DiscordBotNotifier sends notifications using a native Discord Bot. The session is created once and reused. Channel IDs are cached per repo slug.

func (*DiscordBotNotifier) GetMetrics

func (n *DiscordBotNotifier) GetMetrics() *Metrics

func (*DiscordBotNotifier) Name

func (n *DiscordBotNotifier) Name() string

func (*DiscordBotNotifier) Notify

func (n *DiscordBotNotifier) Notify(ctx context.Context, notification Notification) error

func (*DiscordBotNotifier) Ping

func (n *DiscordBotNotifier) Ping(ctx context.Context) error

type DiscordWebhookNotifier

type DiscordWebhookNotifier struct {
	WebhookURL string
}

DiscordWebhookNotifier sends notifications to a Discord webhook.

func (*DiscordWebhookNotifier) GetMetrics

func (n *DiscordWebhookNotifier) GetMetrics() *Metrics

func (*DiscordWebhookNotifier) Name

func (n *DiscordWebhookNotifier) Name() string

func (*DiscordWebhookNotifier) Notify

func (n *DiscordWebhookNotifier) Notify(ctx context.Context, notification Notification) error

func (*DiscordWebhookNotifier) Ping

type Dispatcher

type Dispatcher struct {
	// contains filtered or unexported fields
}

Dispatcher handles asynchronous notification delivery via a buffered channel.

func NewDispatcher

func NewDispatcher(n Notifier, bufSize int) *Dispatcher

NewDispatcher creates a Dispatcher with the given buffer size. It starts a background goroutine that drains the channel.

func (*Dispatcher) Close

func (d *Dispatcher) Close()

Close signals the dispatcher to stop after draining remaining items.

func (*Dispatcher) Send

func (d *Dispatcher) Send(ctx context.Context, n Notification)

Send queues a notification for async delivery. Non-blocking if buffer has room; drops the notification with a warning if the buffer is full.

type Factory

type Factory func(cfg map[string]interface{}) (Notifier, error)

Factory is a function that creates a Notifier from generic configuration.

type Metrics

type Metrics struct {
	// contains filtered or unexported fields
}

Metrics tracks notification send/fail/retry counts per notifier.

func NewMetrics

func NewMetrics() *Metrics

NewMetrics creates a new Metrics tracker.

func (*Metrics) LogSummary

func (m *Metrics) LogSummary()

LogSummary writes a summary of all channel metrics at info level.

func (*Metrics) RecordFailed

func (m *Metrics) RecordFailed(name string)

RecordFailed increments the failed counter for the named notifier.

func (*Metrics) RecordRetried

func (m *Metrics) RecordRetried(name string)

RecordRetried increments the retried counter for the named notifier.

func (*Metrics) RecordSent

func (m *Metrics) RecordSent(name string)

RecordSent increments the sent counter for the named notifier.

func (*Metrics) Snapshots

func (m *Metrics) Snapshots() []Snapshot

Snapshots returns a point-in-time copy of all channel metrics.

type MultiNotifier

type MultiNotifier struct {
	// contains filtered or unexported fields
}

MultiNotifier bundles multiple notifiers together with retry and metrics.

func (*MultiNotifier) GetMetrics

func (m *MultiNotifier) GetMetrics() *Metrics

func (*MultiNotifier) Name

func (m *MultiNotifier) Name() string

func (*MultiNotifier) Notify

func (m *MultiNotifier) Notify(ctx context.Context, n Notification) error

func (*MultiNotifier) Ping

func (m *MultiNotifier) Ping(ctx context.Context) error

type NoopNotifier

type NoopNotifier struct {
	// contains filtered or unexported fields
}

NoopNotifier does nothing.

func (*NoopNotifier) GetMetrics

func (n *NoopNotifier) GetMetrics() *Metrics

func (*NoopNotifier) Name

func (n *NoopNotifier) Name() string

func (*NoopNotifier) Notify

func (n *NoopNotifier) Notify(ctx context.Context, notification Notification) error

func (*NoopNotifier) Ping

func (n *NoopNotifier) Ping(ctx context.Context) error

type Notification

type Notification struct {
	Repo       string
	Event      string
	Action     string
	HookName   string
	Message    string
	Stdout     string
	Sender     string
	DeliveryID string
	State      string          // success, failure, pending
	RawPayload json.RawMessage // full GitHub webhook payload for template access
}

Notification represents a rich notification message.

type Notifier

type Notifier interface {
	Notify(ctx context.Context, n Notification) error
	Ping(ctx context.Context) error
	Name() string
	// Metrics returns the metrics tracker for this notifier tree.
	GetMetrics() *Metrics
}

Notifier is the interface for sending notifications.

func NewNotifier

func NewNotifier(cfg Config) Notifier

NewNotifier creates a MultiNotifier based on the enabled list and settings.

type RetryConfig

type RetryConfig struct {
	MaxAttempts int
	BaseDelay   time.Duration
}

RetryConfig controls retry behavior for notifications.

func DefaultRetryConfig

func DefaultRetryConfig() RetryConfig

DefaultRetryConfig returns sensible retry defaults.

type SlackNotifier

type SlackNotifier struct {
	WebhookURL string
}

SlackNotifier sends notifications to a Slack webhook using Block Kit.

func (*SlackNotifier) GetMetrics

func (n *SlackNotifier) GetMetrics() *Metrics

func (*SlackNotifier) Name

func (n *SlackNotifier) Name() string

func (*SlackNotifier) Notify

func (n *SlackNotifier) Notify(ctx context.Context, notification Notification) error

func (*SlackNotifier) Ping

func (n *SlackNotifier) Ping(ctx context.Context) error

type Snapshot

type Snapshot struct {
	Name    string
	Sent    int64
	Failed  int64
	Retried int64
}

Snapshot holds a point-in-time copy of metrics for a single channel.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL