actions

package
v0.43.0 Latest Latest
Warning

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

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

Documentation

Index

Constants

View Source
const (
	LogOutputExtension = ".log"
	LogOutputLocation  = "_lakefs/actions/log"
)

Variables

View Source
var (
	ErrInvalidAction    = errors.New("invalid action")
	ErrInvalidEventType = errors.New("invalid event type")
)
View Source
var (
	ErrWebhookRequestFailed = errors.New("webhook request failed")
	ErrWebhookWrongFormat   = errors.New("webhook wrong format")
)
View Source
var ErrIteratorClosed = errors.New("iterator closed")
View Source
var ErrNotFound = errors.New("not found")
View Source
var ErrUnknownHookType = errors.New("unknown hook type")

Functions

func FormatHookOutputPath

func FormatHookOutputPath(runID, hookRunID string) string

func FormatRunManifestOutputPath

func FormatRunManifestOutputPath(runID string) string

func NewHookRunID

func NewHookRunID(actionIdx, hookIdx int) 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, record graveler.HookRecord) ([]*Action, error)

func MatchedActions

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]interface{} `yaml:"properties"`
}

type ActionOn

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

type DBRunResultIterator

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

func NewDBRunResultIterator

func NewDBRunResultIterator(ctx context.Context, db db.Database, fetchSize int, repositoryID string, branchID, commitID string, after string) *DBRunResultIterator

func (*DBRunResultIterator) Close

func (it *DBRunResultIterator) Close()

func (*DBRunResultIterator) Err

func (it *DBRunResultIterator) Err() error

func (*DBRunResultIterator) Next

func (it *DBRunResultIterator) Next() bool

func (*DBRunResultIterator) Value

func (it *DBRunResultIterator) Value() *RunResult

type DBTaskResultIterator

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

func NewDBTaskResultIterator

func NewDBTaskResultIterator(ctx context.Context, db db.Database, fetchSize int, repositoryID, runID, after string) *DBTaskResultIterator

func (*DBTaskResultIterator) Close

func (it *DBTaskResultIterator) Close()

func (*DBTaskResultIterator) Err

func (it *DBTaskResultIterator) Err() error

func (*DBTaskResultIterator) Next

func (it *DBTaskResultIterator) Next() bool

func (*DBTaskResultIterator) Value

func (it *DBTaskResultIterator) Value() *TaskResult

type Hook

type Hook interface {
	Run(ctx context.Context, record graveler.HookRecord, 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

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

func (*HookOutputWriter) OutputWrite

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 graveler.EventType
	BranchID  graveler.BranchID
}

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, storageNamespace, name string, reader io.Reader, size int64) error
}

type RunManifest

type RunManifest struct {
	Run      RunResult    `json:"run"`
	HooksRun []TaskResult `json:"hooks,omitempty"`
}

type RunResult

type RunResult struct {
	RunID     string    `db:"run_id" json:"run_id"`
	BranchID  string    `db:"branch_id" json:"branch_id"`
	SourceRef string    `db:"source_ref" json:"source_ref"`
	EventType string    `db:"event_type" json:"event_type"`
	StartTime time.Time `db:"start_time" json:"start_time"`
	EndTime   time.Time `db:"end_time" json:"end_time"`
	Passed    bool      `db:"passed" json:"passed"`
	CommitID  string    `db:"commit_id" json:"commit_id,omitempty"`
}

type RunResultIterator

type RunResultIterator interface {
	Next() bool
	Value() *RunResult
	Err() error
	Close()
}

type Service

type Service struct {
	DB     db.Database
	Source Source
	Writer OutputWriter
}

func NewService

func NewService(db db.Database, source Source, writer OutputWriter) *Service

func (*Service) GetRunResult

func (s *Service) GetRunResult(ctx context.Context, repositoryID string, runID string) (*RunResult, error)

func (*Service) GetTaskResult

func (s *Service) GetTaskResult(ctx context.Context, repositoryID string, runID string, hookRunID string) (*TaskResult, error)

func (*Service) ListRunResults

func (s *Service) ListRunResults(ctx context.Context, repositoryID string, branchID, commitID string, after string) (RunResultIterator, error)

func (*Service) ListRunTaskResults

func (s *Service) ListRunTaskResults(ctx context.Context, repositoryID string, runID string, after string) (TaskResultIterator, error)

func (*Service) PostCommitHook

func (s *Service) PostCommitHook(ctx context.Context, record graveler.HookRecord) error

func (*Service) PostMergeHook

func (s *Service) PostMergeHook(ctx context.Context, record graveler.HookRecord) error

func (*Service) PreCommitHook

func (s *Service) PreCommitHook(ctx context.Context, record graveler.HookRecord) error

func (*Service) PreMergeHook

func (s *Service) PreMergeHook(ctx context.Context, record graveler.HookRecord) error

func (*Service) Run

func (s *Service) Run(ctx context.Context, record graveler.HookRecord) error

Run load and run actions based on the event information

func (*Service) UpdateCommitID

func (s *Service) UpdateCommitID(ctx context.Context, repositoryID string, storageNamespace string, runID string, commitID string) error

UpdateCommitID assume record is a post event, we use the PreRunID to update the commit_id and save the run manifest again

type Source

type Source interface {
	List(ctx context.Context, record graveler.HookRecord) ([]string, error)
	Load(ctx context.Context, record graveler.HookRecord, name string) ([]byte, error)
}

type Task

type Task struct {
	RunID     string
	HookRunID string
	Action    *Action
	HookID    string
	Hook      Hook
	Err       error
	StartTime time.Time
	EndTime   time.Time
}

type TaskResult

type TaskResult struct {
	RunID      string    `db:"run_id" json:"run_id"`
	HookRunID  string    `db:"hook_run_id" json:"hook_run_id"`
	HookID     string    `db:"hook_id" json:"hook_id"`
	ActionName string    `db:"action_name" json:"action_name"`
	StartTime  time.Time `db:"start_time" json:"start_time"`
	EndTime    time.Time `db:"end_time" json:"end_time"`
	Passed     bool      `db:"passed" json:"passed"`
}

func (*TaskResult) LogPath

func (r *TaskResult) LogPath() string

type TaskResultIterator

type TaskResultIterator interface {
	Next() bool
	Value() *TaskResult
	Err() error
	Close()
}

type Webhook

type Webhook struct {
	ID          string
	ActionName  string
	URL         string
	Timeout     time.Duration
	QueryParams map[string][]string
}

func (*Webhook) Run

func (w *Webhook) Run(ctx context.Context, record graveler.HookRecord, writer *HookOutputWriter) (err 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,omitempty"`
	CommitMessage  string            `json:"commit_message"`
	Committer      string            `json:"committer"`
	CommitMetadata map[string]string `json:"commit_metadata,omitempty"`
}

Jump to

Keyboard shortcuts

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