MCPcopy Create free account
hub / github.com/github/gh-aw / ParseStringArrayOrExprFromConfig

Function ParseStringArrayOrExprFromConfig

pkg/workflow/config_helpers.go:76–107  ·  view source on GitHub ↗

ParseStringArrayOrExprFromConfig is like ParseStringArrayFromConfig but also accepts a GitHub Actions expression string as a valid value. When the raw value is an expression (starts with "${{" and ends with "}}") it is returned as []string{exprString} so that the handler config builder can later de

(m map[string]any, key string, debugLog *logger.Logger)

Source from the content-addressed store, hash-verified

74//
75// Non-expression bare strings are treated as invalid and nil is returned.
76func ParseStringArrayOrExprFromConfig(m map[string]any, key string, debugLog *logger.Logger) []string {
77 if value, exists := m[key]; exists {
78 if debugLog != nil {
79 debugLog.Printf("Parsing %s from config", key)
80 }
81 // Accept a GitHub Actions expression string: wrap it in a single-element slice.
82 if s, ok := value.(string); ok {
83 if isExpression(s) {
84 if debugLog != nil {
85 debugLog.Printf("Field %s is a GitHub Actions expression, wrapping in single-element array", key)
86 }
87 return []string{s}
88 }
89 // Non-expression string is invalid for an array field.
90 if debugLog != nil {
91 debugLog.Printf("Field %q must be an array or a GitHub Actions expression, ignoring non-expression string: %q", key, s)
92 }
93 return nil
94 }
95 // Handle arrays (existing logic).
96 if strings := parseStringSliceAny(value, debugLog); strings != nil {
97 if len(strings) == 0 && debugLog != nil {
98 debugLog.Printf("No valid %s strings found, returning empty array", key)
99 }
100 if debugLog != nil {
101 debugLog.Printf("Parsed %d %s from config", len(strings), key)
102 }
103 return strings
104 }
105 }
106 return nil
107}
108
109// extractStringFromMap is a generic helper that extracts and validates a string value from a map
110// Returns the string value, or empty string if not present or invalid

Calls 3

isExpressionFunction · 0.85
parseStringSliceAnyFunction · 0.85
PrintfMethod · 0.45

Tested by 2

TestAllListEncodingFormsFunction · 0.68