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

Function validateStringEnumField

pkg/workflow/validation_helpers.go:183–212  ·  view source on GitHub ↗

validateStringEnumField checks that a config field, if present, contains one of the allowed string values. Non-string values and unrecognised strings are removed from the map (treated as absent) and a warning is logged. Use this for fields that are pure string enums with no boolean shorthand. GitHu

(configData map[string]any, fieldName string, allowed []string, debugLog *logger.Logger)

Source from the content-addressed store, hash-verified

181// without enum validation and passed through unchanged; the resolved value is
182// validated at runtime by the safe-output handler.
183func validateStringEnumField(configData map[string]any, fieldName string, allowed []string, debugLog *logger.Logger) {
184 if configData == nil {
185 return
186 }
187 val, exists := configData[fieldName]
188 if !exists || val == nil {
189 return
190 }
191 strVal, ok := val.(string)
192 if !ok {
193 if debugLog != nil {
194 debugLog.Printf("Invalid %s value %v (must be one of %v), ignoring", fieldName, val, allowed)
195 }
196 delete(configData, fieldName)
197 return
198 }
199 // GitHub Actions expressions are validated at runtime by the handler.
200 if containsExpression(strVal) {
201 if debugLog != nil {
202 debugLog.Printf("%s value is a GitHub Actions expression, skipping compile-time enum validation", fieldName)
203 }
204 return
205 }
206 if !slices.Contains(allowed, strVal) {
207 if debugLog != nil {
208 debugLog.Printf("Invalid %s value %v (must be one of %v), ignoring", fieldName, val, allowed)
209 }
210 delete(configData, fieldName)
211 }
212}
213
214// validateNoDuplicateIDs checks that all items have unique IDs extracted by idFunc.
215// The onDuplicate callback creates the error to return when a duplicate is found.

Calls 2

containsExpressionFunction · 0.85
PrintfMethod · 0.45

Tested by 1