MCPcopy Create free account
hub / github.com/bytebase/bytebase / extractCategoryFromExpr

Function extractCategoryFromExpr

backend/api/v1/release_service.go:507–530  ·  view source on GitHub ↗

extractCategoryFromExpr walks the CEL AST to extract the category value.

(expr celast.Expr)

Source from the content-addressed store, hash-verified

505
506// extractCategoryFromExpr walks the CEL AST to extract the category value.
507func extractCategoryFromExpr(expr celast.Expr) (string, error) {
508 switch expr.Kind() {
509 case celast.CallKind:
510 call := expr.AsCall()
511 functionName := call.FunctionName()
512
513 // Handle: category == "value"
514 if functionName == celoperators.Equals {
515 variable, value := getVariableAndValueFromExpr(expr)
516 if variable == "category" {
517 if categoryValue, ok := value.(string); ok {
518 return categoryValue, nil
519 }
520 return "", errors.Errorf("category value must be a string, got %T", value)
521 }
522 return "", errors.Errorf("unsupported filter variable: %s", variable)
523 }
524
525 return "", errors.Errorf("unsupported operator: %s (only '==' is supported)", functionName)
526
527 default:
528 return "", errors.Errorf("unsupported expression type")
529 }
530}
531
532func renderTrain(template, timezone string, t time.Time) (string, error) {
533 // Validate template

Callers 1

parseCategoryFilterFunction · 0.85

Calls 2

ErrorfMethod · 0.80

Tested by

no test coverage detected