|
| 1 | +package view |
| 2 | + |
| 3 | +import ( |
| 4 | + "github.com/google/cel-go/cel" |
| 5 | + "github.com/tektoncd/results/pkg/api/server/cel2sql" |
| 6 | + resultspb "github.com/tektoncd/results/proto/v1alpha2/results_go_proto" |
| 7 | +) |
| 8 | + |
| 9 | +var ( |
| 10 | + typePipelineRun = "tekton.dev/v1beta1.PipelineRun" |
| 11 | + typeTaskRun = "tekton.dev/v1beta1.TaskRun" |
| 12 | + |
| 13 | + typeConstants = map[string]cel2sql.Constant{ |
| 14 | + "PIPELINE_RUN": { |
| 15 | + StringVal: &typePipelineRun, |
| 16 | + }, |
| 17 | + "TASK_RUN": { |
| 18 | + StringVal: &typeTaskRun, |
| 19 | + }, |
| 20 | + } |
| 21 | +) |
| 22 | + |
| 23 | +// NewResultsView return the set of variables and constants available for CEL |
| 24 | +// filters |
| 25 | +func NewResultsView() (*cel2sql.View, error) { |
| 26 | + view := &cel2sql.View{ |
| 27 | + Constants: map[string]cel2sql.Constant{}, |
| 28 | + Fields: map[string]cel2sql.Field{ |
| 29 | + "parent": { |
| 30 | + CELType: cel.StringType, |
| 31 | + SQL: `parent`, |
| 32 | + }, |
| 33 | + "uid": { |
| 34 | + CELType: cel.StringType, |
| 35 | + SQL: `id`, |
| 36 | + }, |
| 37 | + "create_time": { |
| 38 | + CELType: cel2sql.CELTypeTimestamp, |
| 39 | + SQL: `created_time`, |
| 40 | + }, |
| 41 | + "update_time": { |
| 42 | + CELType: cel2sql.CELTypeTimestamp, |
| 43 | + SQL: `updated_time`, |
| 44 | + }, |
| 45 | + "annotations": { |
| 46 | + CELType: cel.MapType(cel.StringType, cel.StringType), |
| 47 | + SQL: `annotations`, |
| 48 | + }, |
| 49 | + "summary": { |
| 50 | + CELType: cel.ObjectType("tekton.results.v1alpha2.RecordSummary"), |
| 51 | + ObjectType: &resultspb.RecordSummary{}, |
| 52 | + SQL: `recordsummary_{{.Field}}`, |
| 53 | + }, |
| 54 | + }, |
| 55 | + } |
| 56 | + for typeName, value := range typeConstants { |
| 57 | + view.Constants[typeName] = value |
| 58 | + } |
| 59 | + for name, value := range resultspb.RecordSummary_Status_value { |
| 60 | + v := value |
| 61 | + view.Constants[name] = cel2sql.Constant{ |
| 62 | + Int32Val: &v, |
| 63 | + } |
| 64 | + } |
| 65 | + return view, nil |
| 66 | +} |
0 commit comments