github.com/shashidharatd/test-infra@v0.0.0-20171006011030-71304e1ca560/velodrome/transform/plugins/count.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 plugins 18 19 import ( 20 "github.com/spf13/cobra" 21 ) 22 23 func NewCountPlugin(runner func(Plugin) error) *cobra.Command { 24 stateCounter := &StatePlugin{} 25 eventCounter := &EventCounterPlugin{} 26 commentsAsEvents := NewFakeCommentPluginWrapper(eventCounter) 27 commentCounter := &CommentCounterPlugin{} 28 authorLoggable := NewMultiplexerPluginWrapper( 29 commentsAsEvents, 30 commentCounter, 31 ) 32 authorLogged := NewAuthorLoggerPluginWrapper(authorLoggable) 33 fullMultiplex := NewMultiplexerPluginWrapper(authorLogged, stateCounter) 34 35 fakeOpen := NewFakeOpenPluginWrapper(fullMultiplex) 36 typeFilter := NewTypeFilterWrapperPlugin(fakeOpen) 37 authorFilter := NewAuthorFilterPluginWrapper(typeFilter) 38 39 cmd := &cobra.Command{ 40 Use: "count", 41 Short: "Count events and number of issues in given state, and for how long", 42 RunE: func(cmd *cobra.Command, args []string) error { 43 if err := eventCounter.CheckFlags(); err != nil { 44 return err 45 } 46 if err := stateCounter.CheckFlags(); err != nil { 47 return err 48 } 49 if err := typeFilter.CheckFlags(); err != nil { 50 return err 51 } 52 if err := commentCounter.CheckFlags(); err != nil { 53 return err 54 } 55 return runner(authorFilter) 56 }, 57 } 58 59 eventCounter.AddFlags(cmd) 60 stateCounter.AddFlags(cmd) 61 commentCounter.AddFlags(cmd) 62 typeFilter.AddFlags(cmd) 63 authorFilter.AddFlags(cmd) 64 authorLogged.AddFlags(cmd) 65 66 return cmd 67 }