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