actions

package
v0.31.2 Latest Latest
Warning

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

Go to latest
Published: Feb 10, 2021 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrInvalidAction    = errors.New("invalid action")
	ErrInvalidEventType = errors.New("invalid event type")
)
View Source
var (
	ErrWebhookRequestFailed = errors.New("webhook request failed")
	ErrWebhookMissingURL    = errors.New("webhook missing url")
)
View Source
var ErrUnknownHookType = errors.New("unknown hook type")

Functions

func NewRunID

func NewRunID(t time.Time) string

Types

type Action

type Action struct {
	Name        string       `yaml:"name"`
	Description string       `yaml:"description"`
	On          OnEvents     `yaml:"on"`
	Hooks       []ActionHook `yaml:"hooks"`
}

func LoadActions

func LoadActions(source Source) ([]*Action, error)

func MatchActions

func MatchActions(actions []*Action, spec MatchSpec) ([]*Action, error)

func ParseAction

func ParseAction(data []byte) (*Action, error)

ParseAction helper function to read, parse and validate Action from a reader

func (*Action) Match

func (a *Action) Match(spec MatchSpec) (bool, error)

func (*Action) Validate

func (a *Action) Validate() error

type ActionHook

type ActionHook struct {
	ID          string            `yaml:"id"`
	Type        string            `yaml:"type"`
	Description string            `yaml:"description"`
	Properties  map[string]string `yaml:"properties"`
}

type ActionOn

type ActionOn struct {
	Branches []string `yaml:"branches"`
}

type Event

type Event struct {
	EventType     EventType
	EventTime     time.Time
	RepositoryID  string
	BranchID      string
	SourceRef     string
	CommitMessage string
	Committer     string
	Metadata      map[string]string
}

type EventType

type EventType string
const (
	EventTypePreCommit EventType = "pre-commit"
	EventTypePreMerge  EventType = "pre-merge"
)

type Hook

type Hook interface {
	Run(ctx context.Context, runID string, event Event, writer OutputWriter) error
}

func NewHook

func NewHook(h HookType, a *Action, ah ActionHook) (Hook, error)

func NewWebhook

func NewWebhook(action *Action, h ActionHook) (Hook, error)

type HookType

type HookType string
const (
	HookTypeWebhook HookType = "webhook"
)

type MatchSpec

type MatchSpec struct {
	EventType EventType
	Branch    string
}

type NewHookFunc

type NewHookFunc func(*Action, ActionHook) (Hook, error)

type OnEvents

type OnEvents struct {
	PreMerge  *ActionOn `yaml:"pre-merge"`
	PreCommit *ActionOn `yaml:"pre-commit"`
}

type OutputWriter

type OutputWriter interface {
	OutputWrite(ctx context.Context, name string, reader io.Reader) error
}

type Source

type Source interface {
	List() []string
	Load(name string) ([]byte, error)
}

type Webhook

type Webhook struct {
	ID         string
	ActionName string
	URL        string
	Timeout    time.Duration
}

func (*Webhook) Run

func (w *Webhook) Run(ctx context.Context, runID string, ed Event, writer OutputWriter) error

type WebhookEventInfo

type WebhookEventInfo struct {
	RunID         string            `json:"run_id"`
	EventType     string            `json:"event_type"`
	EventTime     string            `json:"event_time"`
	ActionName    string            `json:"action_name"`
	HookID        string            `json:"hook_id"`
	RepositoryID  string            `json:"repository_id"`
	BranchID      string            `json:"branch_id"`
	SourceRef     string            `json:"source_ref"`
	CommitMessage string            `json:"commit_message"`
	Committer     string            `json:"committer"`
	Metadata      map[string]string `json:"metadata"`
}

Jump to

Keyboard shortcuts

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