github.com/abayer/test-infra@v0.0.5/velodrome/transform/plugins/multiplexer_wrapper.go (about)

     1  /*
     2  Copyright 2017 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 plugins
    18  
    19  import (
    20  	"k8s.io/test-infra/velodrome/sql"
    21  )
    22  
    23  // MultiplexerPluginWrapper allows registering multiple plugins for events
    24  type MultiplexerPluginWrapper struct {
    25  	plugins []Plugin
    26  }
    27  
    28  var _ Plugin = &MultiplexerPluginWrapper{}
    29  
    30  // NewMultiplexerPluginWrapper is the constructor for MultiplexerPluginWrapper
    31  func NewMultiplexerPluginWrapper(plugins ...Plugin) *MultiplexerPluginWrapper {
    32  	return &MultiplexerPluginWrapper{
    33  		plugins: plugins,
    34  	}
    35  }
    36  
    37  // ReceiveIssue calls plugin.ReceiveIssue() for all plugins
    38  func (m *MultiplexerPluginWrapper) ReceiveIssue(issue sql.Issue) []Point {
    39  	points := []Point{}
    40  
    41  	for _, plugin := range m.plugins {
    42  		points = append(points, plugin.ReceiveIssue(issue)...)
    43  	}
    44  
    45  	return points
    46  }
    47  
    48  // ReceiveIssueEvent calls plugin.ReceiveIssueEvent() for all plugins
    49  func (m *MultiplexerPluginWrapper) ReceiveIssueEvent(event sql.IssueEvent) []Point {
    50  	points := []Point{}
    51  
    52  	for _, plugin := range m.plugins {
    53  		points = append(points, plugin.ReceiveIssueEvent(event)...)
    54  	}
    55  
    56  	return points
    57  }
    58  
    59  // ReceiveComment calls plugin.ReceiveComment() for all plugins
    60  func (m *MultiplexerPluginWrapper) ReceiveComment(comment sql.Comment) []Point {
    61  	points := []Point{}
    62  
    63  	for _, plugin := range m.plugins {
    64  		points = append(points, plugin.ReceiveComment(comment)...)
    65  	}
    66  
    67  	return points
    68  }