github.com/abayer/test-infra@v0.0.5/mungegithub/mungers/matchers/comment/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 comment
    18  
    19  // True is a matcher that is always true
    20  type True struct{}
    21  
    22  // Match returns true no matter what
    23  func (t True) Match(comment *Comment) bool {
    24  	return true
    25  }
    26  
    27  // False is a matcher that is always false
    28  type False struct{}
    29  
    30  // Match returns false no matter what
    31  func (t False) Match(comment *Comment) bool {
    32  	return false
    33  }
    34  
    35  // And makes sure that each match in the list matches (true if empty)
    36  type And []Matcher
    37  
    38  // Match returns true if all the matcher in the list matches
    39  func (a And) Match(comment *Comment) bool {
    40  	for _, matcher := range []Matcher(a) {
    41  		if !matcher.Match(comment) {
    42  			return false
    43  		}
    44  	}
    45  	return true
    46  }
    47  
    48  // Or makes sure that at least one element in the list matches (false if empty)
    49  type Or []Matcher
    50  
    51  // Match returns true if one of the matcher in the list matches
    52  func (o Or) Match(comment *Comment) bool {
    53  	for _, matcher := range []Matcher(o) {
    54  		if matcher.Match(comment) {
    55  			return true
    56  		}
    57  	}
    58  	return false
    59  }
    60  
    61  // Not reverses the effect of the matcher
    62  type Not struct {
    63  	Matcher Matcher
    64  }
    65  
    66  // Match returns true if the matcher would return false, and vice-versa
    67  func (n Not) Match(comment *Comment) bool {
    68  	return !n.Matcher.Match(comment)
    69  }