engine

package
v4.21.0 Latest Latest
Warning

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

Go to latest
Published: Oct 30, 2023 License: LGPL-3.0 Imports: 24 Imported by: 0

README

engine

Documentation

Index

Constants

View Source
const (
	SILENT_MODE  string = "silent"
	VERBOSE_MODE string = "verbose"
)
View Source
const DefaultMockEventAction = "opened"
View Source
const DefaultMockEventName = "pull_request"
View Source
const DefaultMockPrID = 1234

Use only for tests

View Source
const DefaultMockPrNum = 6
View Source
const DefaultMockPrOwner = "foobar"
View Source
const DefaultMockPrRepoName = "default-mock-repo"

Variables

View Source
var DefaultMockCollector, _ = collector.NewCollector("", "distinctId", "pull_request", "runnerName", nil)
View Source
var DefaultMockCtx = context.Background()

Use only for tests

View Source
var DefaultMockEventDetails = &entities.EventDetails{
	EventName:   DefaultMockEventName,
	EventAction: DefaultMockEventAction,
}
View Source
var DefaultMockEventPayload = &github.CheckRunEvent{}
View Source
var DefaultMockLogger = logrus.NewEntry(logrus.New())
View Source
var DefaultMockTargetEntity = &entities.TargetEntity{
	Owner:  DefaultMockPrOwner,
	Repo:   DefaultMockPrRepoName,
	Number: DefaultMockPrNum,
	Kind:   entities.PullRequest,
}

Functions

func ExecConfigurationFile added in v4.10.0

func ExecConfigurationFile(env *Env, file *ReviewpadFile) (ExitStatus, *Program, error)

ExecConfigurationFile processes Pre-condition Lint(file) == nil

func GetDefaultMockPullRequestDetails

func GetDefaultMockPullRequestDetails() *github.PullRequest

func Lint

func Lint(file *ReviewpadFile, reserved []string, logger *logrus.Entry) error

func MockGithubClient

func MockGithubClient(clientOptions []mock.MockBackendOption) *gh.GithubClient

func MustUnmarshal

func MustUnmarshal(data []byte, v interface{})

func MustWriteBytes

func MustWriteBytes(w io.Writer, data []byte)

Types

type CheckState

type CheckState string
const (
	CheckStateError   CheckState = "error"
	CheckStateFailure CheckState = "failure"
	CheckStatePending CheckState = "pending"
	CheckStateSuccess CheckState = "success"
)

type Env

type Env struct {
	Ctx          context.Context
	DryRun       bool
	GithubClient *gh.GithubClient
	Collector    collector.Collector
	Interpreter  Interpreter
	TargetEntity *entities.TargetEntity
	EventDetails *entities.EventDetails
	Logger       *logrus.Entry
}

func MockEnvWith

func MockEnvWith(githubClient *gh.GithubClient, interpreter Interpreter, targetEntity *entities.TargetEntity, eventDetails *entities.EventDetails) (*Env, error)

func NewEvalEnv

func NewEvalEnv(
	ctx context.Context,
	logger *logrus.Entry,
	dryRun bool,
	githubClient *gh.GithubClient,
	collector collector.Collector,
	targetEntity *entities.TargetEntity,
	interpreter Interpreter,
	eventDetails *entities.EventDetails,
) (*Env, error)

type ExitStatus

type ExitStatus int
const ExitStatusFailure ExitStatus = 1
const ExitStatusSuccess ExitStatus = 0

type GroupKind

type GroupKind string
const GroupKindDeveloper GroupKind = "developer"

type GroupType

type GroupType string
const GroupTypeFilter GroupType = "filter"
const GroupTypeStatic GroupType = "static"

type Interpreter

type Interpreter interface {
	ProcessGroup(name string, kind GroupKind, typeOf GroupType, expr, paramExpr, whereExpr string) error
	ProcessLabel(id, name string) error
	ProcessRule(name, spec string) error
	EvalExpr(kind, expr string) (bool, error)
	ExecProgram(program *Program) (ExitStatus, error)
	ExecStatement(statement *Statement) error
	Report(mode string, safeMode bool) error
	ReportMetrics() error
	GetCheckRunConclusion() string
	ProcessIterable(expr string) (lang.Value, error)
	StoreTemporaryVariable(name string, value lang.Value)
	ProcessDictionary(name string, dictionary map[string]string) error
}

type LoadEnv

type LoadEnv struct {
	Visited map[string]bool
	Stack   map[string]bool
}

type NormalizeRule

type NormalizeRule struct {
	Validators   []validator
	Modificators []modificator
}

func NewNormalizeRule

func NewNormalizeRule() *NormalizeRule

func (*NormalizeRule) Do

func (*NormalizeRule) WithModificators

func (n *NormalizeRule) WithModificators(m ...modificator)

func (*NormalizeRule) WithValidators

func (n *NormalizeRule) WithValidators(v ...validator)

type PadCheck added in v4.16.0

type PadCheck struct {
	Severity   string                 `yaml:"severity"`
	Activation string                 `yaml:"activation"`
	Parameters map[string]interface{} `yaml:"parameters"`
}

type PadDictionary added in v4.14.0

type PadDictionary struct {
	Name string            `yaml:"name"`
	Spec map[string]string `yaml:"spec"`
}

type PadGroup

type PadGroup struct {
	Name        string `yaml:"name"`
	Description string `yaml:"description"`
	Kind        string `yaml:"kind"`
	Type        string `yaml:"type"`
	Spec        string `yaml:"spec"`
	Param       string `yaml:"param"`
	Where       string `yaml:"where"`
}

type PadImport

type PadImport struct {
	Url string `yaml:"url"`
}

type PadLabel

type PadLabel struct {
	Name        string `yaml:"name"`
	Color       string `yaml:"color"`
	Description string `yaml:"description"`
}

type PadPipeline

type PadPipeline struct {
	Name        string     `yaml:"name"`
	Description string     `yaml:"description"`
	Trigger     string     `yaml:"trigger"`
	Stages      []PadStage `yaml:"stages"`
}

type PadRule

type PadRule struct {
	Name        string `yaml:"name"`
	Kind        string `yaml:"kind"`
	Description string `yaml:"description"`
	Spec        string `yaml:"spec"`
}

type PadStage

type PadStage struct {
	Actions              []string `yaml:"-"`
	NonNormalizedActions any      `yaml:"actions"`
	Until                string   `yaml:"until"`
}

type PadWorkflow

type PadWorkflow struct {
	Name                 string                      `yaml:"name"`
	On                   []entities.TargetEntityKind `yaml:"on"`
	Description          string                      `yaml:"description"`
	AlwaysRun            bool                        `yaml:"always-run"`
	Rules                []PadWorkflowRule           `yaml:"-"`
	Actions              []string                    `yaml:"-"`
	Runs                 []PadWorkflowRunBlock       `yaml:"-"`
	NonNormalizedRules   any                         `yaml:"if"`
	NonNormalizedActions any                         `yaml:"then"`
	NonNormalizedElse    any                         `yaml:"else"`
	NonNormalizedRun     any                         `yaml:"run"`
}

type PadWorkflowRule

type PadWorkflowRule struct {
	Rule         string   `yaml:"rule"`
	ExtraActions []string `yaml:"extra-actions" mapstructure:"extra-actions"`
}

type PadWorkflowRunBlock added in v4.7.0

type PadWorkflowRunBlock struct {
	If      []PadWorkflowRule
	Then    []PadWorkflowRunBlock
	Else    []PadWorkflowRunBlock
	Actions []string
	ForEach *PadWorkflowRunForEachBlock
}

type PadWorkflowRunForEachBlock added in v4.12.0

type PadWorkflowRunForEachBlock struct {
	Key   string
	Value string
	In    string
	Do    []PadWorkflowRunBlock
}

type Program

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

func BuildProgram

func BuildProgram(statements []*Statement) *Program

func EvalCommand

func EvalCommand(command string, env *Env) (*Program, error)

EvalCommand generates the program to be executed when a command is received

func EvalConfigurationFile

func EvalConfigurationFile(file *ReviewpadFile, env *Env) (*Program, error)

EvalConfigurationFile generates the program to be executed Pre-condition Lint(file) == nil

func (*Program) GetProgramStatements

func (p *Program) GetProgramStatements() []*Statement

type ReviewpadFile

type ReviewpadFile struct {
	Mode           string              `yaml:"mode"`
	IgnoreErrors   *bool               `yaml:"ignore-errors"`
	MetricsOnMerge *bool               `yaml:"metrics-on-merge"`
	Imports        []PadImport         `yaml:"imports"`
	Extends        []string            `yaml:"extends"`
	Groups         []PadGroup          `yaml:"groups"`
	Checks         map[string]PadCheck `yaml:"checks"`
	Rules          []PadRule           `yaml:"rules"`
	Labels         map[string]PadLabel `yaml:"labels"`
	Workflows      []PadWorkflow       `yaml:"workflows"`
	Pipelines      []PadPipeline       `yaml:"pipelines"`
	Recipes        map[string]*bool    `yaml:"recipes"`
	Dictionaries   []PadDictionary     `yaml:"dictionaries"`
}

func Load

func Load(ctx context.Context, logger *logrus.Entry, githubClient *gh.GithubClient, data []byte) (*ReviewpadFile, error)

type Statement

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

func BuildStatement

func BuildStatement(code string) *Statement

func (*Statement) GetStatementCode

func (s *Statement) GetStatementCode() string

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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