MCPcopy Create free account
hub / github.com/github/gh-aw / parseOnSection

Method parseOnSection

pkg/workflow/trigger_parser.go:770–1029  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

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.
770func (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 {

Calls 13

IsLabelOnlyEventFunction · 0.92
QuoteCronExpressionsFunction · 0.92
parseReactionConfigFunction · 0.85
isValidReactionFunction · 0.85
getValidReactionsFunction · 0.85
excludeMapKeysFunction · 0.85
mergeCommandOtherEventsFunction · 0.85
PrintfMethod · 0.45