validateCommandTriggerConflicts checks that command triggers are not used with conflicting events
(frontmatter map[string]any)
| 20 | |
| 21 | // validateCommandTriggerConflicts checks that command triggers are not used with conflicting events |
| 22 | func validateCommandTriggerConflicts(frontmatter map[string]any) error { |
| 23 | // Check if 'on' field exists and is a map |
| 24 | onValue, hasOn := frontmatter["on"] |
| 25 | if !hasOn { |
| 26 | return nil |
| 27 | } |
| 28 | |
| 29 | onMap, isMap := onValue.(map[string]any) |
| 30 | if !isMap { |
| 31 | return nil |
| 32 | } |
| 33 | |
| 34 | // Check if command trigger is present |
| 35 | commandValue, hasCommand := onMap["command"] |
| 36 | if !hasCommand || commandValue == nil { |
| 37 | return nil |
| 38 | } |
| 39 | |
| 40 | schemaTriggersLog.Print("Validating command trigger conflicts") |
| 41 | |
| 42 | // List of conflicting events - but we'll check if issues/pull_request are label-only or ready_for_review |
| 43 | conflictingEvents := []string{"issues", "issue_comment", "pull_request", "pull_request_review_comment"} |
| 44 | |
| 45 | // Check for conflicts |
| 46 | var foundConflicts []string |
| 47 | for _, eventName := range conflictingEvents { |
| 48 | if eventValue, hasEvent := onMap[eventName]; hasEvent && eventValue != nil { |
| 49 | // Special case: allow issues/pull_request events with non-conflicting types (labeled/unlabeled/ready_for_review) |
| 50 | if eventName == "issues" || eventName == "pull_request" { |
| 51 | if IsNonConflictingCommandEvent(eventValue) { |
| 52 | schemaTriggersLog.Printf("Allowing non-conflicting %s event with command trigger", eventName) |
| 53 | continue // Allow this - it doesn't conflict with command triggers |
| 54 | } |
| 55 | } |
| 56 | foundConflicts = append(foundConflicts, eventName) |
| 57 | } |
| 58 | } |
| 59 | |
| 60 | if len(foundConflicts) > 0 { |
| 61 | schemaTriggersLog.Printf("Command trigger conflicts found: %s", strings.Join(foundConflicts, ", ")) |
| 62 | if len(foundConflicts) == 1 { |
| 63 | return fmt.Errorf("command trigger cannot be used with '%s' event in the same workflow. Command triggers are designed to respond to slash commands in comments and should not be combined with event-based triggers for issues or pull requests", foundConflicts[0]) |
| 64 | } |
| 65 | return fmt.Errorf("command trigger cannot be used with these events in the same workflow: %s. Command triggers are designed to respond to slash commands in comments and should not be combined with event-based triggers for issues or pull requests", strings.Join(foundConflicts, ", ")) |
| 66 | } |
| 67 | |
| 68 | return nil |
| 69 | } |
| 70 | |
| 71 | // IsLabelOnlyEvent checks if an event configuration only contains labeled/unlabeled types |
| 72 | // This is exported for use in the compiler to validate command trigger combinations |
no test coverage detected