parseSubmitPullRequestReviewConfig handles submit-pull-request-review configuration
(outputMap map[string]any)
| 24 | |
| 25 | // parseSubmitPullRequestReviewConfig handles submit-pull-request-review configuration |
| 26 | func (c *Compiler) parseSubmitPullRequestReviewConfig(outputMap map[string]any) *SubmitPullRequestReviewConfig { |
| 27 | if _, exists := outputMap["submit-pull-request-review"]; !exists { |
| 28 | submitPRReviewLog.Printf("Configuration not found") |
| 29 | return nil |
| 30 | } |
| 31 | |
| 32 | submitPRReviewLog.Printf("Parsing submit PR review configuration") |
| 33 | |
| 34 | configData := outputMap["submit-pull-request-review"] |
| 35 | config := &SubmitPullRequestReviewConfig{} |
| 36 | |
| 37 | if configMap, ok := configData.(map[string]any); ok { |
| 38 | // Parse common base fields with default max of 1 |
| 39 | c.parseBaseSafeOutputConfig(configMap, &config.BaseSafeOutputConfig, 1) |
| 40 | |
| 41 | // Parse target config (target, target-repo, allowed-repos) |
| 42 | // Uses parseTargetRepoWithValidation to disallow wildcard "*" for target-repo |
| 43 | if target, exists := configMap["target"]; exists { |
| 44 | if targetStr, ok := target.(string); ok { |
| 45 | config.Target = targetStr |
| 46 | } |
| 47 | } |
| 48 | |
| 49 | targetRepoSlug, isInvalid := parseTargetRepoWithValidation(configMap) |
| 50 | if isInvalid { |
| 51 | return nil // Invalid configuration, return nil to cause validation error |
| 52 | } |
| 53 | config.TargetRepoSlug = targetRepoSlug |
| 54 | config.AllowedRepos = ParseStringArrayFromConfig(configMap, "allowed-repos", submitPRReviewLog) |
| 55 | |
| 56 | // Parse footer configuration (string: "always"/"none"/"if-body", or bool for backward compat) |
| 57 | if footer, exists := configMap["footer"]; exists { |
| 58 | switch f := footer.(type) { |
| 59 | case string: |
| 60 | // Validate string values: "always", "none", "if-body" |
| 61 | if f == "always" || f == "none" || f == "if-body" { |
| 62 | config.Footer = &f |
| 63 | submitPRReviewLog.Printf("Footer control: %s", f) |
| 64 | } else { |
| 65 | submitPRReviewLog.Printf("Invalid footer value: %s (must be 'always', 'none', or 'if-body')", f) |
| 66 | } |
| 67 | case bool: |
| 68 | // Map boolean to string: true -> "always", false -> "none" |
| 69 | var footerStr string |
| 70 | if f { |
| 71 | footerStr = "always" |
| 72 | } else { |
| 73 | footerStr = "none" |
| 74 | } |
| 75 | config.Footer = &footerStr |
| 76 | submitPRReviewLog.Printf("Footer control (mapped from bool): %s", footerStr) |
| 77 | } |
| 78 | } |
| 79 | |
| 80 | // Parse allowed-events configuration |
| 81 | if allowedEvents, exists := configMap["allowed-events"]; exists { |
| 82 | eventsSlice, ok := allowedEvents.([]any) |
| 83 | if !ok { |