parseCommentsConfig handles add-comment configuration
(outputMap map[string]any)
| 29 | |
| 30 | // parseCommentsConfig handles add-comment configuration |
| 31 | func (c *Compiler) parseCommentsConfig(outputMap map[string]any) *AddCommentsConfig { |
| 32 | // Check if the key exists |
| 33 | if _, exists := outputMap["add-comment"]; !exists { |
| 34 | return nil |
| 35 | } |
| 36 | |
| 37 | // Get config data for pre-processing before YAML unmarshaling |
| 38 | configData, _ := outputMap["add-comment"].(map[string]any) |
| 39 | |
| 40 | if err := preprocessHideOlderCommentsConfig(configData, addCommentLog); err != nil { |
| 41 | addCommentLog.Printf("Invalid hide-older-comments configuration: %v", err) |
| 42 | return nil |
| 43 | } |
| 44 | |
| 45 | // Pre-process templatable bool fields |
| 46 | if err := preprocessBoolFieldAsString(configData, "hide-older-comments", addCommentLog); err != nil { |
| 47 | addCommentLog.Printf("Invalid hide-older-comments value: %v", err) |
| 48 | return nil |
| 49 | } |
| 50 | if err := preprocessBoolFieldAsString(configData, "footer", addCommentLog); err != nil { |
| 51 | addCommentLog.Printf("Invalid footer value: %v", err) |
| 52 | return nil |
| 53 | } |
| 54 | |
| 55 | // Pre-process templatable int fields |
| 56 | if err := preprocessIntFieldAsString(configData, "max", addCommentLog); err != nil { |
| 57 | addCommentLog.Printf("Invalid max value: %v", err) |
| 58 | return nil |
| 59 | } |
| 60 | |
| 61 | // Pre-process list fields that also accept a GitHub Actions expression string. |
| 62 | if err := preprocessStringArrayFieldAsTemplatable(configData, "allowed-repos", addCommentLog); err != nil { |
| 63 | addCommentLog.Printf("Invalid allowed-repos value: %v", err) |
| 64 | return nil |
| 65 | } |
| 66 | |
| 67 | config := parseConfigScaffold(outputMap, "add-comment", addCommentLog, func(err error) *AddCommentsConfig { |
| 68 | addCommentLog.Printf("Failed to unmarshal config: %v", err) |
| 69 | // For backward compatibility, handle nil/empty config |
| 70 | return &AddCommentsConfig{} |
| 71 | }) |
| 72 | if config == nil { |
| 73 | return nil |
| 74 | } |
| 75 | |
| 76 | // Set default max if not specified |
| 77 | if config.Max == nil { |
| 78 | config.Max = defaultIntStr(1) |
| 79 | } |
| 80 | |
| 81 | return config |
| 82 | } |
| 83 | |
| 84 | func preprocessHideOlderCommentsConfig(configData map[string]any, debugLog *logger.Logger) error { |
| 85 | if configData == nil { |