github.com/abayer/test-infra@v0.0.5/mungegithub/mungers/matchers/event/operators.go (about) 1 /* 2 Copyright 2016 The Kubernetes Authors. 3 4 Licensed under the Apache License, Version 2.0 (the "License"); 5 you may not use this file except in compliance with the License. 6 You may obtain a copy of the License at 7 8 http://www.apache.org/licenses/LICENSE-2.0 9 10 Unless required by applicable law or agreed to in writing, software 11 distributed under the License is distributed on an "AS IS" BASIS, 12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 See the License for the specific language governing permissions and 14 limitations under the License. 15 */ 16 17 package event 18 19 import "github.com/google/go-github/github" 20 21 // True is a matcher that is always true 22 type True struct{} 23 24 // Match returns true no matter what 25 func (t True) Match(event *github.IssueEvent) bool { 26 return true 27 } 28 29 // False is a matcher that is always false 30 type False struct{} 31 32 // Match returns false no matter what 33 func (t False) Match(event *github.IssueEvent) bool { 34 return false 35 } 36 37 // And makes sure that each match in the list matches (true if empty) 38 type And []Matcher 39 40 // Match returns true if all the matcher in the list matches 41 func (a And) Match(event *github.IssueEvent) bool { 42 for _, matcher := range []Matcher(a) { 43 if !matcher.Match(event) { 44 return false 45 } 46 } 47 return true 48 } 49 50 // Or makes sure that at least one element in the list matches (false if empty) 51 type Or []Matcher 52 53 // Match returns true if one of the matcher in the list matches 54 func (o Or) Match(event *github.IssueEvent) bool { 55 for _, matcher := range []Matcher(o) { 56 if matcher.Match(event) { 57 return true 58 } 59 } 60 return false 61 } 62 63 // Not reverses the effect of the matcher 64 type Not struct { 65 Matcher Matcher 66 } 67 68 // Match returns true if the matcher would return false, and vice-versa 69 func (n Not) Match(event *github.IssueEvent) bool { 70 return !n.Matcher.Match(event) 71 }