parseCreateEntityConfig parses create-* config scaffolding shared by issue/discussion/PR handlers. Parameters: - outputMap: full safe-output map from frontmatter parsing. - configKey: create-* key to parse (for example "create-issue"). - opts: shared preprocessing configuration for bool/int/expires
( outputMap map[string]any, configKey string, opts CreateParseOptions, debugLog *logger.Logger, onError func(error) *T, preUnmarshal func(map[string]any) bool, postUnmarshal func(map[string]any, *T, bool), )
| 30 | // - postUnmarshal is optional (may be nil). When provided, it is invoked after successful |
| 31 | // unmarshaling and receives expiresDisabled (true when expires was explicitly set to false). |
| 32 | func parseCreateEntityConfig[T any]( |
| 33 | outputMap map[string]any, |
| 34 | configKey string, |
| 35 | opts CreateParseOptions, |
| 36 | debugLog *logger.Logger, |
| 37 | onError func(error) *T, |
| 38 | preUnmarshal func(map[string]any) bool, |
| 39 | postUnmarshal func(map[string]any, *T, bool), |
| 40 | ) *T { |
| 41 | if _, exists := outputMap[configKey]; !exists { |
| 42 | return nil |
| 43 | } |
| 44 | |
| 45 | configDataAny := outputMap[configKey] |
| 46 | configData, isMap := configDataAny.(map[string]any) |
| 47 | if !isMap { |
| 48 | configData = nil |
| 49 | } |
| 50 | if preUnmarshal != nil && !preUnmarshal(configData) { |
| 51 | return nil |
| 52 | } |
| 53 | |
| 54 | expiresDisabled := false |
| 55 | if opts.HandleExpires { |
| 56 | expiresDisabled = preprocessExpiresField(configData, debugLog) |
| 57 | } |
| 58 | |
| 59 | for _, field := range opts.BoolFields { |
| 60 | if err := preprocessBoolFieldAsString(configData, field, debugLog); err != nil { |
| 61 | debugLog.Printf("Invalid %s value: %v", field, err) |
| 62 | return nil |
| 63 | } |
| 64 | } |
| 65 | |
| 66 | for _, field := range opts.IntFields { |
| 67 | if err := preprocessIntFieldAsString(configData, field, debugLog); err != nil { |
| 68 | debugLog.Printf("Invalid %s value: %v", field, err) |
| 69 | return nil |
| 70 | } |
| 71 | } |
| 72 | |
| 73 | config := parseConfigScaffold(outputMap, configKey, debugLog, onError) |
| 74 | if config == nil { |
| 75 | return nil |
| 76 | } |
| 77 | |
| 78 | if postUnmarshal != nil { |
| 79 | postUnmarshal(configData, config, expiresDisabled) |
| 80 | } |
| 81 | |
| 82 | return config |
| 83 | } |
no test coverage detected