parseDispatchWorkflowConfig handles dispatch-workflow configuration
(outputMap map[string]any)
| 19 | |
| 20 | // parseDispatchWorkflowConfig handles dispatch-workflow configuration |
| 21 | func (c *Compiler) parseDispatchWorkflowConfig(outputMap map[string]any) *DispatchWorkflowConfig { |
| 22 | dispatchWorkflowLog.Print("Parsing dispatch-workflow configuration") |
| 23 | if configData, exists := outputMap["dispatch-workflow"]; exists { |
| 24 | dispatchWorkflowConfig := &DispatchWorkflowConfig{} |
| 25 | |
| 26 | // Check if it's a list of workflow names (array format) |
| 27 | if workflowsArray, ok := configData.([]any); ok { |
| 28 | dispatchWorkflowLog.Printf("Found dispatch-workflow as array with %d workflows", len(workflowsArray)) |
| 29 | for _, workflow := range workflowsArray { |
| 30 | if workflowStr, ok := workflow.(string); ok { |
| 31 | dispatchWorkflowConfig.Workflows = append(dispatchWorkflowConfig.Workflows, workflowStr) |
| 32 | } |
| 33 | } |
| 34 | // Set default max to 1 |
| 35 | dispatchWorkflowConfig.Max = defaultIntStr(1) |
| 36 | return dispatchWorkflowConfig |
| 37 | } |
| 38 | |
| 39 | // Check if it's a map with configuration options |
| 40 | if configMap, ok := configData.(map[string]any); ok { |
| 41 | dispatchWorkflowLog.Print("Found dispatch-workflow config map") |
| 42 | |
| 43 | // Parse workflows list |
| 44 | if workflows, exists := configMap["workflows"]; exists { |
| 45 | if workflowsArray, ok := workflows.([]any); ok { |
| 46 | for _, workflow := range workflowsArray { |
| 47 | if workflowStr, ok := workflow.(string); ok { |
| 48 | dispatchWorkflowConfig.Workflows = append(dispatchWorkflowConfig.Workflows, workflowStr) |
| 49 | } |
| 50 | } |
| 51 | } |
| 52 | } |
| 53 | |
| 54 | // Parse common base fields with default max of 1 |
| 55 | c.parseBaseSafeOutputConfig(configMap, &dispatchWorkflowConfig.BaseSafeOutputConfig, 1) |
| 56 | |
| 57 | // Parse target-ref (optional ref for cross-repo dispatch) |
| 58 | if targetRef, ok := configMap["target-ref"].(string); ok && targetRef != "" { |
| 59 | dispatchWorkflowConfig.TargetRef = targetRef |
| 60 | } |
| 61 | |
| 62 | // Parse target-repo (optional cross-repo dispatch target) |
| 63 | dispatchWorkflowConfig.TargetRepoSlug = extractStringFromMap(configMap, "target-repo", dispatchWorkflowLog) |
| 64 | dispatchWorkflowConfig.AllowedRepos = ParseStringArrayOrExprFromConfig(configMap, "allowed-repos", dispatchWorkflowLog) |
| 65 | |
| 66 | // Cap max at 50 (absolute maximum allowed) – only for literal integer values |
| 67 | if maxVal := templatableIntValue(dispatchWorkflowConfig.Max); maxVal > 50 { |
| 68 | dispatchWorkflowLog.Printf("Max value %d exceeds limit, capping at 50", maxVal) |
| 69 | dispatchWorkflowConfig.Max = defaultIntStr(50) |
| 70 | } |
| 71 | |
| 72 | dispatchWorkflowLog.Printf("Parsed dispatch-workflow config: max=%v, workflows=%v", |
| 73 | dispatchWorkflowConfig.Max, dispatchWorkflowConfig.Workflows) |
| 74 | return dispatchWorkflowConfig |
| 75 | } |
| 76 | } |
| 77 | |
| 78 | return nil |