goordinator

package
v0.14.0 Latest Latest
Warning

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

Go to latest
Published: Mar 14, 2024 License: AGPL-3.0 Imports: 23 Imported by: 0

Documentation

Index

Constants

View Source
const (
	MatchResultUndefined MatchResult = 0
	EventSourceMismatch              = iota
	RuleMismatch
	Match
)
View Source
const DefRetryTimeout = 2 * time.Hour
View Source
const DefTimeout = 24 * time.Hour

DefTimeout is used as timeout for runs when the passed context has no deadline set.

Variables

This section is empty.

Functions

func WithActionRoutineDeferFunc

func WithActionRoutineDeferFunc(fn func()) func(*EvLoop)

WithActionRoutineDeferFunc sets a function to be run when an go-routine that executes an action returns. It can be used to set a panic handler. Because it does not pass any arguments, there is probably no other good usecase for it. :-)

Types

type ActionConfig

type ActionConfig interface {
	// Render runs renderFunc for all configuration options of the
	// action that are templated and returns a runnable action.
	Render(event action.Event, renderFunc func(string) (string, error)) (action.Runner, error)
	// String returns a short representation of the ActionConfig
	String() string
	// String returns a formatted detailed description.
	DetailedString() string
}

ActionConfig is an interface for an action that is executed as part of a Rule.

type EvLoop

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

EvLoop receives events and triggers matching actions. Actions are executed asynchronously in go-routines and are retried until DefRetryTimeout expired.

func NewEventLoop

func NewEventLoop(eventChan <-chan *github.Event, rules []*Rule, opts ...func(*EvLoop)) *EvLoop

func (*EvLoop) Start

func (e *EvLoop) Start()

func (*EvLoop) Stop

func (e *EvLoop) Stop()

Stop stops the event loop and waits until all scheduled go-routines terminated.

type Event added in v0.8.0

type Event struct {
	JSON     []byte
	Provider string

	// Github hook fields, if the value is not available they are empty
	// strings.
	DeliveryID      string
	EventType       string
	RepositoryOwner string
	Repository      string
	BaseBranch      string
	CommitID        string
	Branch          string
	// PullRequestNr is 0 if it's not available
	PullRequestNr int

	LogFields []zap.Field
}

Event is processed by the event-loop and used for templating actions. It's public fields are accessible via template statements defined in the goordinater config file.

func (*Event) GetPullRequestNr added in v0.8.0

func (e *Event) GetPullRequestNr() int

func (*Event) GetRepository added in v0.8.0

func (e *Event) GetRepository() string

func (*Event) GetRepositoryOwner added in v0.8.0

func (e *Event) GetRepositoryOwner() string

func (*Event) String added in v0.8.0

func (e *Event) String() string

type MatchResult

type MatchResult uint8

MatchResult represents the result matching a rule against an event.

func (*MatchResult) String

func (m *MatchResult) String() string

type Retryer added in v0.8.0

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

Retryer executes a function repeatedly until it was successful or it's context was cancelled.

func NewRetryer added in v0.8.0

func NewRetryer() *Retryer

func (*Retryer) Run added in v0.8.0

func (r *Retryer) Run(ctx context.Context, fn func(context.Context) error, logF []zap.Field) error

Run executes fn until it was successful, it returned an error that does not wrap goorderr.RetryableError or the execution was aborted via the context. If the context has no deadline set, it will be set to DefTimeout.

func (*Retryer) Stop added in v0.8.0

func (r *Retryer) Stop()

Stop notifies all Run() methods to terminate. It does not wait for their termination.

type Rule

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

Rule defines the condition that must apply for an event and the actions that are run when conditions match.

func NewRule

func NewRule(name, eventProvider, jqQuery string, actions []ActionConfig) (*Rule, error)

func (*Rule) DetailedString

func (r *Rule) DetailedString() string

func (*Rule) Match

func (r *Rule) Match(ctx context.Context, event *Event) (MatchResult, error)

Match returns Match if the event.Provider matches the Rule.EventSource and the filter-query of the rule evalutes to true for JSON representation of the event.

func (*Rule) String

func (r *Rule) String() string

func (*Rule) TemplateActions

func (r *Rule) TemplateActions(_ context.Context, event *Event) ([]action.Runner, error)

TemplateActions templates the filter query of the rule for the specific event.

type Rules

type Rules []*Rule

func RulesFromCfg

func RulesFromCfg(cfg *cfg.Config, ghClient *githubclt.Client) (Rules, error)

RulesFromCfg instantiates Rules from a rulesCfg configuration.

func (Rules) String

func (rr Rules) String() string

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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