1
0
Fork 0
mirror of https://code.forgejo.org/forgejo/runner.git synced 2025-09-15 18:57:01 +00:00

fix #127 - force eval as a boolean (#131)

This commit is contained in:
Casey Lee 2020-03-06 11:30:39 -08:00 committed by GitHub
parent 965f86d04e
commit c64bbd5c93
3 changed files with 25 additions and 0 deletions

View file

@ -231,11 +231,14 @@ func (rc *RunContext) isEnabled(ctx context.Context) bool {
// EvalBool evaluates an expression against current run context
func (rc *RunContext) EvalBool(expr string) bool {
if expr != "" {
//v, err := rc.ExprEval.Evaluate(fmt.Sprintf("if (%s) { true } else { false }", expr))
expr := fmt.Sprintf("Boolean(%s)", expr)
v, err := rc.ExprEval.Evaluate(expr)
if err != nil {
log.Errorf("Error evaluating expression '%s' - %v", expr, err)
return false
}
log.Debugf("expression '%s' evaluated to '%s'", expr, v)
return v == "true"
}
return true