IsNonConflictingCommandEvent checks if a pull_request/issues event configuration only contains types that do not conflict with command (slash_command/command) triggers. Allowed types: labeled, unlabeled, ready_for_review
(eventValue any)
| 115 | // only contains types that do not conflict with command (slash_command/command) triggers. |
| 116 | // Allowed types: labeled, unlabeled, ready_for_review |
| 117 | func IsNonConflictingCommandEvent(eventValue any) bool { |
| 118 | // Event can be a map with types field |
| 119 | eventMap, isMap := eventValue.(map[string]any) |
| 120 | if !isMap { |
| 121 | schemaTriggersLog.Print("IsNonConflictingCommandEvent: event value is not a map, returning false") |
| 122 | return false |
| 123 | } |
| 124 | |
| 125 | // Get the types field |
| 126 | typesValue, hasTypes := eventMap["types"] |
| 127 | if !hasTypes { |
| 128 | schemaTriggersLog.Print("IsNonConflictingCommandEvent: no types field found, returning false") |
| 129 | return false |
| 130 | } |
| 131 | |
| 132 | // Types should be an array |
| 133 | typesArray, isArray := typesValue.([]any) |
| 134 | if !isArray { |
| 135 | return false |
| 136 | } |
| 137 | |
| 138 | if len(typesArray) == 0 { |
| 139 | return false |
| 140 | } |
| 141 | |
| 142 | for _, typeValue := range typesArray { |
| 143 | typeStr, isString := typeValue.(string) |
| 144 | if !isString { |
| 145 | return false |
| 146 | } |
| 147 | switch typeStr { |
| 148 | case "labeled", "unlabeled", "ready_for_review": |
| 149 | // allowed |
| 150 | default: |
| 151 | schemaTriggersLog.Printf("IsNonConflictingCommandEvent: type %q conflicts with command triggers, returning false", typeStr) |
| 152 | return false |
| 153 | } |
| 154 | } |
| 155 | |
| 156 | schemaTriggersLog.Print("IsNonConflictingCommandEvent: all types are non-conflicting, returning true") |
| 157 | return true |
| 158 | } |
no test coverage detected