actions

package
v0.32.0 Latest Latest
Warning

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

Go to latest
Published: Feb 17, 2021 License: Apache-2.0 Imports: 15 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 (
	ErrNotFound = errors.New("not found")
)
View Source
var ErrUnknownHookType = errors.New("unknown hook type")

Functions

func FormatHookOutputPath added in v0.32.0

func FormatHookOutputPath(runID, actionName, hookID string) string

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(ctx context.Context, source Source) ([]*Action, error)

func MatchedActions added in v0.32.0

func MatchedActions(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        HookType          `yaml:"type"`
	Description string            `yaml:"description"`
	Properties  map[string]string `yaml:"properties"`
}

type ActionOn

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

type Deps added in v0.32.0

type Deps struct {
	Source Source
	Output OutputWriter
}

type Event

type Event struct {
	EventID       uuid.UUID
	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 FileRef added in v0.32.0

type FileRef struct {
	Path    string
	Address string
}

type Hook

type Hook interface {
	Run(ctx context.Context, event Event, writer *HookOutputWriter) error
}

Hook is the abstraction of the basic user-configured runnable building-stone

func NewHook

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

func NewWebhook

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

type HookOutputWriter added in v0.32.0

type HookOutputWriter struct {
	RunID      string
	ActionName string
	HookID     string
	Writer     OutputWriter
}

func (*HookOutputWriter) OutputWrite added in v0.32.0

func (h *HookOutputWriter) OutputWrite(ctx context.Context, reader io.Reader, size int64) error

type HookType

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

type MatchSpec

type MatchSpec struct {
	EventType EventType
	Branch    string
}

type NewHookFunc

type NewHookFunc func(ActionHook, *Action) (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, size int64) error
}

type RunResult added in v0.32.0

type RunResult struct {
	RunID      string
	BranchID   string
	OnRef      string
	ActionName string
	EventType  EventType
	StartTime  time.Time
	EndTime    time.Time
	Passed     bool
}

type RunResultIter added in v0.32.0

type RunResultIter interface {
	Next() bool
	Value() RunResult
	// SeekGE seeks by start-time
	SeekGE(time.Time)
	Err() error
	Close()
}

type Service added in v0.32.0

type Service struct {
	DB db.Database
}

func New added in v0.32.0

func New(db db.Database) *Service

func (*Service) Run added in v0.32.0

func (s *Service) Run(ctx context.Context, event Event, deps Deps) error

type Source

type Source interface {
	List(ctx context.Context) ([]FileRef, error)
	Load(ctx context.Context, name FileRef) ([]byte, error)
}

type Task added in v0.32.0

type Task struct {
	RunID  string
	Action *Action
	HookID string
	Hook   Hook
}

type TaskResult added in v0.32.0

type TaskResult struct {
	RunID      string
	HookID     string
	HookType   string
	ActionName string
	StartTime  time.Time
	EndTime    time.Time
	Passed     bool
}

type TaskResultIter added in v0.32.0

type TaskResultIter interface {
	Next() bool
	Value() TaskResult
	// SeekGE seeks by start-time
	SeekGE(time.Time)
	Err() error
	Close()
}

type Webhook

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

func (*Webhook) Run

func (w *Webhook) Run(ctx context.Context, event Event, writer *HookOutputWriter) error

type WebhookEventInfo

type WebhookEventInfo struct {
	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