notifier

package
v0.0.0-...-efd23c5 Latest Latest
Warning

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

Go to latest
Published: Oct 30, 2024 License: BSD-3-Clause Imports: 13 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ChatNotifierConfig

type ChatNotifierConfig struct {
	RoomID string `json:"room"`
}

Configuration for ChatNotifier.

func (*ChatNotifierConfig) Validate

func (c *ChatNotifierConfig) Validate() error

Validate the ChatNotifierConfig.

type Config

type Config struct {

	// Configuration for filtering out messages. Exactly one of these should
	// be specified.
	Filter          string   `json:"filter,omitempty"`
	IncludeMsgTypes []string `json:"includeMsgTypes,omitempty"`

	// Exactly one of these should be specified.
	Email    *EmailNotifierConfig    `json:"email,omitempty"`
	Chat     *ChatNotifierConfig     `json:"chat,omitempty"`
	Monorail *MonorailNotifierConfig `json:"monorail,omitempty"`
	PubSub   *PubSubNotifierConfig   `json:"pubsub,omitempty"`

	// If present, all messages inherit this subject line.
	Subject string `json:"subject,omitempty"`
}

Config provides configuration for a Notifier.

func (*Config) Copy

func (c *Config) Copy() *Config

Create a copy of this Config.

func (*Config) Create

func (c *Config) Create(ctx context.Context, client *http.Client, emailer emailclient.Client, chatBotConfigReader chatbot.ConfigReader) (Notifier, Filter, []string, string, error)

Create a Notifier from the Config.

func (*Config) Validate

func (c *Config) Validate() error

Validate the Config.

type EmailNotifierConfig

type EmailNotifierConfig struct {
	// List of email addresses to notify. Required.
	Emails []string `json:"emails"`
}

Configuration for EmailNotifier.

func (*EmailNotifierConfig) Validate

func (c *EmailNotifierConfig) Validate() error

Validate the EmailNotifierConfig.

type Filter

type Filter int
const (
	// Message filters.
	FILTER_SILENT Filter = iota
	FILTER_ERROR
	FILTER_WARNING
	FILTER_INFO
	FILTER_DEBUG
)

func ParseFilter

func ParseFilter(f string) (Filter, error)

func (Filter) ShouldSend

func (f Filter) ShouldSend(t Severity) bool

func (Filter) String

func (f Filter) String() string

type Message

type Message struct {
	// Subject line of the message (required). This is ignored in favor of
	// the default in single-thread mode.
	Subject string
	// Body of the message (required).
	Body string
	// Severity of the message. May cause the message not to be sent,
	// depending on filter settings.
	Severity Severity
	// Type of message. This is used with the optional IncludeMsgTypes to
	// send only specific types of messages.
	Type string
	// ExtraRecipients who should also be sent this Message. Not supported for
	// all types of notification.
	ExtraRecipients []string
}

Message represents a message to be sent through one or more Notifiers.

func (*Message) Validate

func (m *Message) Validate() error

Validate the Message.

type MonorailNotifierConfig

type MonorailNotifierConfig struct {
	// Project name under which to file bugs. Required.
	Project string `json:"project"`

	// Owner of bugs filed in Monorail. Required.
	Owner string `json:"owner"`

	// List of people to CC on bugs filed in Monorail. Optional.
	CC []string `json:"cc,omitempty"`

	// List of components to apply to the bugs. Optional.
	Components []string `json:"components,omitempty"`

	// List of labels to apply to bugs filed in Monorail. Optional.
	Labels []string `json:"labels,omitempty"`
}

Configuration for a MonorailNotifier.

func (*MonorailNotifierConfig) Validate

func (c *MonorailNotifierConfig) Validate() error

Validate the MonorailNotifierConfig.

type Notifier

type Notifier interface {
	// Send the given message to the given thread. This should be safe to
	// run in a goroutine.
	Send(ctx context.Context, thread string, msg *Message) error
}

Notifier is an interface used for sending notifications from an AutoRoller.

func ChatNotifier

func ChatNotifier(roomId string, configReader chatbot.ConfigReader) (Notifier, error)

ChatNotifier returns a Notifier which sends email to interested parties.

func EmailNotifier

func EmailNotifier(emails []string, emailer emailclient.Client, markup string) (Notifier, error)

EmailNotifier returns a Notifier which sends email to interested parties. Sends the same ViewAction markup with each message.

func MonorailNotifier

func MonorailNotifier(c *http.Client, project, owner string, cc, components, labels []string) (Notifier, error)

MonorailNotifier returns a Notifier which files bugs in Monorail.

func PubSubNotifier

func PubSubNotifier(ctx context.Context, topic string) (Notifier, error)

PubSubNotifier returns a Notifier which sends messages via PubSub.

type PubSubNotifierConfig

type PubSubNotifierConfig struct {
	Topic string `json:"topic"`
}

Configuration for a PubSubNotifier.

func (*PubSubNotifierConfig) Validate

func (c *PubSubNotifierConfig) Validate() error

Validate the PubSubNotifierConfig.

type Router

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

Router is a struct used for sending notification through zero or more Notifiers.

func NewRouter

func NewRouter(client *http.Client, emailer emailclient.Client, chatBotConfigReader chatbot.ConfigReader) *Router

Return a Router instance.

func (*Router) Add

func (r *Router) Add(n Notifier, f Filter, includeMsgTypes []string, singleThreadSubject string)

Add a new Notifier, which filters according to the given Filter. If singleThreadSubject is provided, that will be used as the subject for all Messages, ignoring their Subject field.

func (*Router) AddFromConfig

func (r *Router) AddFromConfig(ctx context.Context, c *Config) error

Add a new Notifier based on the given Config.

func (*Router) AddFromConfigs

func (r *Router) AddFromConfigs(ctx context.Context, cfgs []*Config) error

Add all of the Notifiers specified by the given Configs.

func (*Router) Send

func (r *Router) Send(ctx context.Context, msg *Message) error

Send a notification.

type Severity

type Severity int
const (
	// Severity of messages
	SEVERITY_ERROR Severity = iota
	SEVERITY_WARNING
	SEVERITY_INFO
	SEVERITY_DEBUG
)

func (Severity) String

func (s Severity) String() string

Jump to

Keyboard shortcuts

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