Documentation
¶
Overview ¶
c matches character c (c != '\\', '-', ']') '\\' c matches character c lo '-' hi matches character c for lo <= c <= hi
Index ¶
- Constants
- Variables
- func AllTrue(values []cty.Value) (cty.Value, error)
- func AnyJSONToCtyValue(jsonStr []byte) (cty.Value, error)
- func AnyTrue(values []cty.Value) (cty.Value, error)
- func CreateSourceEvent(rawEvent map[string]any, source string, event string, action string) ([]byte, string, error)
- func DecodeCallBlock(ctx context.Context, hop *HopAST, on *OnAST, block *hcl.Block, idx int, ...) error
- func DecodeConditionalAttr(attr *hcl.Attribute, defaultValue bool, ctx *hcl.EvalContext) (bool, error)
- func DecodeHopsBody(ctx context.Context, hop *HopAST, hopsContent *hcl.BodyContent, ...) error
- func DecodeNameAttr(attr *hcl.Attribute) (string, error)
- func DecodeOnBlock(ctx context.Context, hop *HopAST, block *hcl.Block, idx int, ...) error
- func DecodeParamBlock(block *hcl.Block, task *TaskAST, hop *HopAST, evalctx *hcl.EvalContext) error
- func DecodeScheduleBlock(block *hcl.Block, hop *HopAST, evalctx *hcl.EvalContext) error
- func DecodeSchedules(hop *HopAST, hopsContent *hcl.BodyContent, evalctx *hcl.EvalContext) error
- func DecodeTaskBlock(ctx context.Context, hop *HopAST, block *hcl.Block, evalctx *hcl.EvalContext) error
- func DecodeTasks(ctx context.Context, hop *HopAST, hopsContent *hcl.BodyContent, ...) error
- func Env(envVarName, defaultValue cty.Value) (cty.Value, error)
- func Glob(values, patterns cty.Value) (cty.Value, error)
- func ReadHopsFileContents(hopsFileContent []FileContent) (*hcl.BodyContent, string, error)
- func TemplateVersion(template string) (string, error)
- func ValidateLabels(labels ...string) error
- func XGlob(values, patterns cty.Value) (cty.Value, error)
- type CallAST
- type ConditionalAST
- type DoneAST
- type FileContent
- type HopAST
- type HopsFiles
- type OnAST
- type ParamAST
- type ScheduleAST
- type SourceMeta
- type TaskAST
Constants ¶
const ( InvalidRequired string = "Required" InvalidNotString string = "Should be a string" InvalidNotText string = "Should be text" InvalidNotNumber string = "Should be a number" InvalidNotBool string = "Should be a boolean" )
const MaxLabelLength = 50
Variables ¶
var ( ErrorAttr = "error" ResultAttr = "result" IfAttr = "if" NameAttr = "name" HopSchema = &hcl.BodySchema{ Attributes: []hcl.AttributeSchema{}, Blocks: []hcl.BlockHeaderSchema{ { Type: OnID, LabelNames: []string{"eventType"}, }, { Type: TaskID, LabelNames: []string{"Name"}, }, { Type: ScheduleID, LabelNames: []string{"Name"}, }, }, } OnID = "on" OnSchema = &hcl.BodySchema{ Blocks: []hcl.BlockHeaderSchema{ { Type: CallID, LabelNames: []string{"taskType"}, }, { Type: DoneID, }, }, Attributes: []hcl.AttributeSchema{ {Name: "name", Required: false}, {Name: IfAttr, Required: false}, }, } CallID = "call" DoneID = "done" TaskID = "task" ParamID = "param" // Schema defined via tags on the struct ScheduleID = "schedule" // Schema defined via tags on the struct )
var AllTrueFunc = function.New(&function.Spec{ VarParam: &function.Parameter{ Name: "clauses", Type: cty.Bool, }, Type: function.StaticReturnType(cty.Bool), Impl: func(args []cty.Value, retType cty.Type) (cty.Value, error) { return AllTrue(args) }, })
alltrue() takes a variable number of bool arguments and returns true if all of them are true.
var AnyTrueFunc = function.New(&function.Spec{ VarParam: &function.Parameter{ Name: "clauses", Type: cty.Bool, }, Type: function.StaticReturnType(cty.Bool), Impl: func(args []cty.Value, retType cty.Type) (cty.Value, error) { if len(args) == 0 { return cty.False, nil } for _, clause := range args { if clause.True() { return cty.True, nil } } return cty.False, nil }, })
anytrue() takes a variable number of bool arguments and returns true if any of them are true.
var DefaultFunctions = map[string]function.Function{ "abs": stdlib.AbsoluteFunc, "alltrue": AllTrueFunc, "anytrue": AnyTrueFunc, "versiontmpl": VersionTemplateFunc, "can": tryfunc.CanFunc, "ceil": stdlib.CeilFunc, "chomp": stdlib.ChompFunc, "coalesce": stdlib.CoalesceFunc, "compact": stdlib.CompactFunc, "concat": stdlib.ConcatFunc, "csv": stdlib.CSVDecodeFunc, "env": EnvFunc, "flatten": stdlib.FlattenFunc, "floor": stdlib.FloorFunc, "format": stdlib.FormatFunc, "formatdate": stdlib.FormatDateFunc, "glob": GlobFunc, "indent": stdlib.IndentFunc, "index": stdlib.IndexFunc, "int": stdlib.IntFunc, "join": stdlib.JoinFunc, "jsondecode": stdlib.JSONDecodeFunc, "jsonencode": stdlib.JSONEncodeFunc, "keys": stdlib.KeysFunc, "length": stdlib.LengthFunc, "lookup": stdlib.LookupFunc, "lower": stdlib.LowerFunc, "max": stdlib.MaxFunc, "merge": stdlib.MergeFunc, "min": stdlib.MinFunc, "range": stdlib.RangeFunc, "regex": stdlib.RegexAllFunc, "regexreplace": stdlib.RegexReplaceFunc, "replace": stdlib.ReplaceFunc, "reverse": stdlib.ReverseFunc, "setintersection": stdlib.SetIntersectionFunc, "setproduct": stdlib.SetProductFunc, "setunion": stdlib.SetUnionFunc, "slice": stdlib.SliceFunc, "sort": stdlib.SortFunc, "split": stdlib.SplitFunc, "strlen": stdlib.StrlenFunc, "substr": stdlib.SubstrFunc, "timeadd": stdlib.TimeAddFunc, "title": stdlib.TitleFunc, "tobool": stdlib.MakeToFunc(cty.Bool), "tolist": stdlib.MakeToFunc(cty.List(cty.DynamicPseudoType)), "tomap": stdlib.MakeToFunc(cty.Map(cty.DynamicPseudoType)), "tonumber": stdlib.MakeToFunc(cty.Number), "toset": stdlib.MakeToFunc(cty.Set(cty.DynamicPseudoType)), "tostring": stdlib.MakeToFunc(cty.String), "trim": stdlib.TrimFunc, "trimprefix": stdlib.TrimPrefixFunc, "trimspace": stdlib.TrimSpaceFunc, "trimsuffix": stdlib.TrimSuffixFunc, "try": tryfunc.TryFunc, "upper": stdlib.UpperFunc, "values": stdlib.ValuesFunc, "xglob": ExclusiveGlobFunc, "zipmap": stdlib.ZipmapFunc, }
TODO: Add encode/decode b64
var EnvFunc = function.New(&function.Spec{ Params: []function.Parameter{ { Name: "envVarName", Type: cty.String, }, { Name: "defaultValue", Type: cty.String, }, }, Type: function.StaticReturnType(cty.String), Impl: func(args []cty.Value, retType cty.Type) (cty.Value, error) { envVarName := args[0] defaultValue := args[1] return Env(envVarName, defaultValue) }, })
EnvFunc is a cty.Function that returns an env var or the default value if it doesn't exist
var ExclusiveGlobFunc = function.New(&function.Spec{ Params: []function.Parameter{ { Name: "patterns", Type: cty.DynamicPseudoType, }, { Name: "values", Type: cty.DynamicPseudoType, }, }, Type: function.StaticReturnType(cty.Bool), Impl: func(args []cty.Value, retType cty.Type) (cty.Value, error) { values := args[0] patterns := args[1] return XGlob(values, patterns) }, })
A cty.Function that matches a string or list of strings against a glob pattern or list of glob patterns. Returns true if _all_ values match at least one pattern.
var GlobFunc = function.New(&function.Spec{ Params: []function.Parameter{ { Name: "patterns", Type: cty.DynamicPseudoType, }, { Name: "values", Type: cty.DynamicPseudoType, }, }, Type: function.StaticReturnType(cty.Bool), Impl: func(args []cty.Value, retType cty.Type) (cty.Value, error) { values := args[0] patterns := args[1] return Glob(values, patterns) }, })
GlobFunc is a cty.Function that matches a string or list of strings against a glob pattern or list of glob patterns. Returns true if _any_ values match at least one pattern.
var VersionTemplateFunc = function.New(&function.Spec{ Params: []function.Parameter{ { Name: "template", Type: cty.String, }, }, Type: function.StaticReturnType(cty.String), Impl: func(args []cty.Value, retType cty.Type) (cty.Value, error) { templateVal := args[0] template := templateVal.AsString() version, err := TemplateVersion(template) return cty.StringVal(version), err }, })
VersionTemplateFunc generates a calver or pet version according to a template
Functions ¶
func AnyJSONToCtyValue ¶
TODO: This method effectively parses the JSON string twice. Once via unmarshal called directly, then again via ctyjson.ImpliedType which runs a decoder. It is likely worth the time to write a decoder that directly takes the unmarshalled json and manually maps to cty values. This function is quite expensive as an overall portion of the runtime. Taking around 200-250µs for a single change event (around 20-25% of hops parsing time).
func CreateSourceEvent ¶
func DecodeCallBlock ¶
func DecodeConditionalAttr ¶
func DecodeHopsBody ¶
func DecodeNameAttr ¶
func DecodeOnBlock ¶
func DecodeParamBlock ¶
func DecodeScheduleBlock ¶ added in v0.7.0
func DecodeSchedules ¶ added in v0.7.0
func DecodeTaskBlock ¶
func DecodeTasks ¶
func ReadHopsFileContents ¶ added in v0.3.0
func ReadHopsFileContents(hopsFileContent []FileContent) (*hcl.BodyContent, string, error)
func TemplateVersion ¶ added in v0.3.0
func ValidateLabels ¶
Types ¶
type CallAST ¶
type CallAST struct { Slug string TaskType string Name string Inputs []byte ConditionalAST }
type ConditionalAST ¶
type ConditionalAST struct {
IfClause bool
}
type FileContent ¶ added in v0.3.0
type HopAST ¶
type HopAST struct { Ons []OnAST Schedules []ScheduleAST SlugRegister map[string]bool StartedAt time.Time Tasks []TaskAST }
func ParseHopsSchedules ¶ added in v0.7.0
func ParseHopsTasks ¶
func (*HopAST) ListSchedules ¶ added in v0.7.0
func (h *HopAST) ListSchedules() []ScheduleAST
type HopsFiles ¶ added in v0.3.0
type HopsFiles struct { Hash string BodyContent *hcl.BodyContent Files []FileContent }
func ReadHopsFilePath ¶ added in v0.3.0
ReadHopsFilePath loads and pre-parses the content of .hops files either from a single file or from all .hops files in a directory. It returns a merged hcl.Body and a sha hash of the contents
type ParamAST ¶
type ParamAST struct { // We use HCL tags to auto-decode as params need very little custom decoding logic Name string `hcl:"name,label" json:"name"` DisplayName string `hcl:"display_name,optional" json:"display_name"` Type string `hcl:"type,optional" json:"type"` Default any `hcl:"default,optional" json:"default"` Help string `hcl:"help,optional" json:"help"` Flag string `hcl:"flag,optional" json:"flag"` ShortFlag string `hcl:"shortflag,optional" json:"shortflag"` Required bool `hcl:"required,optional" json:"required"` }
type ScheduleAST ¶ added in v0.7.0
type SourceMeta ¶
type TaskAST ¶
type TaskAST struct { Name string `json:"name"` DisplayName string `json:"display_name"` Summary string `json:"summary"` Description string `json:"description"` Emoji string `json:"emoji"` Params []ParamAST `json:"params"` }
func (*TaskAST) ValidateInput ¶
ValidateInput validates a struct of param inputs against a task
Returns a map of parameter names with an array of validation error messages if any. Map will be empty (but not nil) if all input is valid.