1
1
package config
2
2
3
3
import (
4
+ "context"
4
5
"errors"
5
6
"fmt"
7
+ "log/slog"
6
8
"reflect"
7
9
8
10
"github.com/expr-lang/expr"
@@ -12,6 +14,7 @@ import (
12
14
"github.com/jippi/scm-engine/pkg/stdlib"
13
15
"github.com/jippi/scm-engine/pkg/tui"
14
16
"github.com/jippi/scm-engine/pkg/types"
17
+ slogctx "github.com/veqryn/slog-context"
15
18
)
16
19
17
20
// labelType is a custom type for our enum
@@ -24,20 +27,28 @@ const (
24
27
25
28
type Labels []* Label
26
29
27
- func (labels Labels ) Evaluate (evalContext scm.EvalContext ) ([]scm.EvaluationResult , error ) {
30
+ func (labels Labels ) Evaluate (ctx context. Context , evalContext scm.EvalContext ) ([]scm.EvaluationResult , error ) {
28
31
var results []scm.EvaluationResult
29
32
30
33
// Evaluate labels
31
34
for _ , label := range labels {
32
- evaluationResult , err := label .Evaluate (evalContext )
35
+ ctx := slogctx .With (ctx , slog .String ("label_name" , label .Name ))
36
+
37
+ slogctx .Debug (ctx , "Evaluating label" )
38
+
39
+ evaluationResult , err := label .Evaluate (ctx , evalContext )
33
40
if err != nil {
34
41
return nil , fmt .Errorf ("label: %s; %w" , label .Name , err )
35
42
}
36
43
37
44
if evaluationResult == nil {
45
+ slogctx .Debug (ctx , "Label evaluated negatively, skipping" )
46
+
38
47
continue
39
48
}
40
49
50
+ slogctx .Debug (ctx , "Label evaluation done" , slog .Any ("label_eval_result" , evaluationResult ))
51
+
41
52
results = append (results , evaluationResult ... )
42
53
}
43
54
@@ -183,21 +194,21 @@ func (p *Label) initialize(evalContext scm.EvalContext) error {
183
194
return nil
184
195
}
185
196
186
- func (p * Label ) ShouldSkip (evalContext scm.EvalContext ) (bool , error ) {
197
+ func (p * Label ) ShouldSkip (ctx context. Context , evalContext scm.EvalContext ) (bool , error ) {
187
198
if err := p .initialize (evalContext ); err != nil {
188
199
return true , err
189
200
}
190
201
191
- return runAndCheckBool (p .skipIfCompiled , evalContext )
202
+ return runAndCheckBool (ctx , p .skipIfCompiled , evalContext )
192
203
}
193
204
194
- func (p * Label ) Evaluate (evalContext scm.EvalContext ) ([]scm.EvaluationResult , error ) {
205
+ func (p * Label ) Evaluate (ctx context. Context , evalContext scm.EvalContext ) ([]scm.EvaluationResult , error ) {
195
206
if err := p .initialize (evalContext ); err != nil {
196
207
return nil , fmt .Errorf ("failed to initialize expr script engine: %w" , err )
197
208
}
198
209
199
210
// Check if the label should be skipped
200
- if skip , err := p .ShouldSkip (evalContext ); err != nil || skip {
211
+ if skip , err := p .ShouldSkip (ctx , evalContext ); err != nil || skip {
201
212
return nil , err
202
213
}
203
214
@@ -260,7 +271,7 @@ func (p Label) resultForLabel(name string, matched bool) scm.EvaluationResult {
260
271
}
261
272
}
262
273
263
- func runAndCheckBool (program * vm.Program , evalContext scm.EvalContext ) (bool , error ) {
274
+ func runAndCheckBool (ctx context. Context , program * vm.Program , evalContext scm.EvalContext ) (bool , error ) {
264
275
if program == nil {
265
276
return false , nil
266
277
}
@@ -272,6 +283,8 @@ func runAndCheckBool(program *vm.Program, evalContext scm.EvalContext) (bool, er
272
283
273
284
switch outputValue := output .(type ) {
274
285
case bool :
286
+ slogctx .Debug (ctx , "script eval done" , slog .Bool ("script_outcome" , outputValue ))
287
+
275
288
return outputValue , nil
276
289
277
290
default :
0 commit comments