parseAddReviewerConfig handles add-reviewer configuration
(outputMap map[string]any)
| 19 | |
| 20 | // parseAddReviewerConfig handles add-reviewer configuration |
| 21 | func (c *Compiler) parseAddReviewerConfig(outputMap map[string]any) *AddReviewerConfig { |
| 22 | // Check if the key exists |
| 23 | if _, exists := outputMap["add-reviewer"]; !exists { |
| 24 | return nil |
| 25 | } |
| 26 | |
| 27 | // Get config data for pre-processing before YAML unmarshaling |
| 28 | configData, _ := outputMap["add-reviewer"].(map[string]any) |
| 29 | |
| 30 | // Pre-process reviewers fields to convert single string to array BEFORE unmarshaling |
| 31 | if configData != nil { |
| 32 | for _, key := range []string{"allowed-reviewers", "reviewers"} { |
| 33 | if val, exists := configData[key]; exists { |
| 34 | if str, ok := val.(string); ok { |
| 35 | configData[key] = []string{str} |
| 36 | } |
| 37 | } |
| 38 | } |
| 39 | for _, key := range []string{"allowed-team-reviewers", "team-reviewers"} { |
| 40 | if val, exists := configData[key]; exists { |
| 41 | if str, ok := val.(string); ok { |
| 42 | configData[key] = []string{str} |
| 43 | } |
| 44 | } |
| 45 | } |
| 46 | } |
| 47 | |
| 48 | // Pre-process templatable int fields |
| 49 | if err := preprocessIntFieldAsString(configData, "max", addReviewerLog); err != nil { |
| 50 | addReviewerLog.Printf("Invalid max value: %v", err) |
| 51 | return nil |
| 52 | } |
| 53 | |
| 54 | config := parseConfigScaffold(outputMap, "add-reviewer", addReviewerLog, func(err error) *AddReviewerConfig { |
| 55 | addReviewerLog.Printf("Failed to unmarshal config: %v", err) |
| 56 | // For backward compatibility, handle nil/empty config |
| 57 | return &AddReviewerConfig{} |
| 58 | }) |
| 59 | if config == nil { |
| 60 | return nil |
| 61 | } |
| 62 | |
| 63 | // Set default max if not specified |
| 64 | if config.Max == nil { |
| 65 | config.Max = defaultIntStr(3) |
| 66 | } |
| 67 | |
| 68 | // Fallback from deprecated field names to preferred names |
| 69 | if len(config.AllowedReviewers) == 0 { |
| 70 | config.AllowedReviewers = config.Reviewers |
| 71 | } |
| 72 | if len(config.AllowedTeamReviewers) == 0 { |
| 73 | config.AllowedTeamReviewers = config.TeamReviewers |
| 74 | } |
| 75 | |
| 76 | addReviewerLog.Printf("Parsed add-reviewer config: allowed_reviewers=%d, target=%s", len(config.AllowedReviewers), config.Target) |
| 77 | |
| 78 | return config |
no test coverage detected