parseCreatePullRequestsConfig handles only create-pull-request (singular) configuration
(outputMap map[string]any)
| 72 | |
| 73 | // parseCreatePullRequestsConfig handles only create-pull-request (singular) configuration |
| 74 | func (c *Compiler) parseCreatePullRequestsConfig(outputMap map[string]any) *CreatePullRequestsConfig { |
| 75 | // Check for singular form only |
| 76 | if _, exists := outputMap["create-pull-request"]; !exists { |
| 77 | createPRLog.Print("No create-pull-request configuration found") |
| 78 | return nil |
| 79 | } |
| 80 | |
| 81 | var protectedFilesExclude []string |
| 82 | config := parseCreateEntityConfig( |
| 83 | outputMap, |
| 84 | "create-pull-request", |
| 85 | CreateParseOptions{ |
| 86 | BoolFields: []string{"draft", "allow-empty", "auto-merge", "footer", "auto-close-issue", "close-older-pull-requests"}, |
| 87 | IntFields: []string{"max"}, |
| 88 | HandleExpires: true, |
| 89 | }, |
| 90 | createPRLog, |
| 91 | func(err error) *CreatePullRequestsConfig { |
| 92 | createPRLog.Printf("Failed to unmarshal config: %v", err) |
| 93 | // For backward compatibility, handle nil/empty config |
| 94 | return &CreatePullRequestsConfig{} |
| 95 | }, |
| 96 | func(configData map[string]any) bool { |
| 97 | coerceStringOrArrayFields(configData, createPRStringOrArrayFields, createPRLog) |
| 98 | |
| 99 | // Pre-process protected-files: supports string enum OR object form {policy, exclude}. |
| 100 | // Object form is preprocessed to extract the policy (stored back as string) and |
| 101 | // the exclude list (stored in a local variable and assigned to the config after unmarshaling). |
| 102 | protectedFilesExclude = preprocessProtectedFilesField(configData, createPRLog) |
| 103 | |
| 104 | // Validate protected-files string enum after object-form preprocessing. |
| 105 | validateStringEnumField(configData, "protected-files", []string{"blocked", "allowed", "fallback-to-issue", "request_review"}, createPRLog) |
| 106 | |
| 107 | // Pre-process patch-format: valid values are "bundle" (default) and "am". |
| 108 | validateStringEnumField(configData, "patch-format", []string{"am", "bundle"}, createPRLog) |
| 109 | |
| 110 | // Pre-process list fields that also accept a GitHub Actions expression string. |
| 111 | // An expression is wrapped in a single-element []string so the []string struct field |
| 112 | // can receive it after YAML unmarshaling; the handler config builder later re-emits it |
| 113 | // as a JSON string for runtime evaluation. |
| 114 | for _, field := range createPRExpressionArrayFields { |
| 115 | if err := preprocessStringArrayFieldAsTemplatable(configData, field, createPRLog); err != nil { |
| 116 | createPRLog.Printf("Invalid %s value: %v", field, err) |
| 117 | return false |
| 118 | } |
| 119 | } |
| 120 | |
| 121 | return true |
| 122 | }, |
| 123 | func(_ map[string]any, config *CreatePullRequestsConfig, expiresDisabled bool) { |
| 124 | if expiresDisabled { |
| 125 | createPRLog.Print("Pull request expiration disabled") |
| 126 | } |
| 127 | |
| 128 | // Log expires if configured |
| 129 | if config.Expires > 0 { |
| 130 | createPRLog.Printf("Pull request expiration configured: %d hours", config.Expires) |
| 131 | } |