injectWorkflowDispatchForIssue adds workflow_dispatch trigger with issue_number input
(onSection string)
| 464 | |
| 465 | // injectWorkflowDispatchForIssue adds workflow_dispatch trigger with issue_number input |
| 466 | func (c *Compiler) injectWorkflowDispatchForIssue(onSection string) string { |
| 467 | toolsLog.Print("Injecting workflow_dispatch trigger for issue workflows") |
| 468 | // Parse the existing on section to understand its structure |
| 469 | var onData map[string]any |
| 470 | if err := yaml.Unmarshal([]byte(onSection), &onData); err != nil { |
| 471 | // If parsing fails, append workflow_dispatch manually |
| 472 | return onSection + "\n workflow_dispatch:\n inputs:\n issue_number:\n description: 'Issue number for trial mode'\n required: true\n type: string" |
| 473 | } |
| 474 | |
| 475 | // Get the 'on' section |
| 476 | if onMap, exists := onData["on"]; exists { |
| 477 | if triggers, ok := onMap.(map[string]any); ok { |
| 478 | // Add workflow_dispatch with issue_number input |
| 479 | triggers["workflow_dispatch"] = map[string]any{ |
| 480 | "inputs": map[string]any{ |
| 481 | "issue_number": map[string]any{ |
| 482 | "description": "Issue number for trial mode", |
| 483 | "required": true, |
| 484 | "type": "string", |
| 485 | }, |
| 486 | }, |
| 487 | } |
| 488 | |
| 489 | // Convert back to YAML |
| 490 | updatedOnData := map[string]any{"on": triggers} |
| 491 | if yamlBytes, err := yaml.Marshal(updatedOnData); err == nil { |
| 492 | yamlStr := string(yamlBytes) |
| 493 | // Keep "on" quoted as it's a YAML boolean keyword |
| 494 | return strings.TrimSuffix(yamlStr, "\n") |
| 495 | } |
| 496 | } |
| 497 | } |
| 498 | |
| 499 | // Fallback: append workflow_dispatch manually |
| 500 | return onSection + "\n workflow_dispatch:\n inputs:\n issue_number:\n description: 'Issue number for trial mode'\n required: true\n type: string" |
| 501 | } |
| 502 | |
| 503 | // replaceIssueNumberReferences replaces github.event.issue.number with inputs.issue_number in YAML content |
| 504 | func (c *Compiler) replaceIssueNumberReferences(yamlContent string) string { |