parseOnSection handles parsing of the "on" section from frontmatter, extracting command triggers, reactions, and stop-after configurations while detecting conflicts with other event types.
(frontmatter map[string]any, workflowData *WorkflowData, markdownPath string)
| 768 | // parseOnSection handles parsing of the "on" section from frontmatter, extracting command triggers, |
| 769 | // reactions, and stop-after configurations while detecting conflicts with other event types. |
| 770 | func (c *Compiler) parseOnSection(frontmatter map[string]any, workflowData *WorkflowData, markdownPath string) error { |
| 771 | triggerParserLog.Printf("Parsing on section: workflow=%s, markdownPath=%s", workflowData.Name, markdownPath) |
| 772 | // Check if "slash_command" or "command" (deprecated) is used as a trigger in the "on" section |
| 773 | // Also extract "reaction" from the "on" section |
| 774 | var hasCommand bool |
| 775 | var hasLabelCommand bool |
| 776 | var hasReaction bool |
| 777 | var hasStopAfter bool |
| 778 | var hasStatusComment bool |
| 779 | var otherEvents map[string]any |
| 780 | |
| 781 | // Use cached On field from ParsedFrontmatter if available, otherwise fall back to map access |
| 782 | var onValue any |
| 783 | var exists bool |
| 784 | if workflowData.ParsedFrontmatter != nil && workflowData.ParsedFrontmatter.On != nil { |
| 785 | onValue = workflowData.ParsedFrontmatter.On |
| 786 | exists = true |
| 787 | } else { |
| 788 | onValue, exists = frontmatter["on"] |
| 789 | } |
| 790 | |
| 791 | if exists { |
| 792 | // Check for new format: on.slash_command/on.command and on.reaction |
| 793 | if onMap, ok := onValue.(map[string]any); ok { |
| 794 | // Check for stop-after in the on section |
| 795 | if _, hasStopAfterKey := onMap["stop-after"]; hasStopAfterKey { |
| 796 | hasStopAfter = true |
| 797 | } |
| 798 | |
| 799 | // Extract reaction from on section |
| 800 | if reactionValue, hasReactionField := onMap["reaction"]; hasReactionField { |
| 801 | hasReaction = true |
| 802 | reactionStr, reactionIssues, reactionPullRequests, reactionDiscussions, err := parseReactionConfig(reactionValue) |
| 803 | if err != nil { |
| 804 | return err |
| 805 | } |
| 806 | // Validate reaction value |
| 807 | if !isValidReaction(reactionStr) { |
| 808 | return fmt.Errorf("invalid reaction value '%s': must be one of %v", reactionStr, getValidReactions()) |
| 809 | } |
| 810 | // Set AIReaction even if it's "none" - "none" explicitly disables reactions |
| 811 | workflowData.AIReaction = reactionStr |
| 812 | workflowData.ReactionIssues = reactionIssues |
| 813 | workflowData.ReactionPullRequests = reactionPullRequests |
| 814 | workflowData.ReactionDiscussions = reactionDiscussions |
| 815 | } |
| 816 | |
| 817 | // Extract status-comment from on section |
| 818 | if statusCommentValue, hasStatusCommentField := onMap["status-comment"]; hasStatusCommentField { |
| 819 | hasStatusComment = true |
| 820 | if statusCommentBool, ok := statusCommentValue.(bool); ok { |
| 821 | workflowData.StatusComment = &statusCommentBool |
| 822 | triggerParserLog.Printf("status-comment set to: %v", statusCommentBool) |
| 823 | } else if statusCommentMap, ok := statusCommentValue.(map[string]any); ok { |
| 824 | statusCommentIssues := true |
| 825 | if issuesValue, hasIssues := statusCommentMap["issues"]; hasIssues { |
| 826 | issuesBool, ok := issuesValue.(bool) |
| 827 | if !ok { |