github.com/abayer/test-infra@v0.0.5/velodrome/transform/plugins/fake_comment_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  // FakeCommentPluginWrapper is a plugin wrapper creating fake "commented" events
    24  type FakeCommentPluginWrapper struct {
    25  	plugin Plugin
    26  }
    27  
    28  var _ Plugin = &FakeCommentPluginWrapper{}
    29  
    30  // NewFakeCommentPluginWrapper is the constructor for FakeCommentPluginWrapper
    31  func NewFakeCommentPluginWrapper(plugin Plugin) *FakeCommentPluginWrapper {
    32  	return &FakeCommentPluginWrapper{
    33  		plugin: plugin,
    34  	}
    35  }
    36  
    37  // ReceiveIssue is a wrapper on plugin.ReceiveIssue()
    38  func (o *FakeCommentPluginWrapper) ReceiveIssue(issue sql.Issue) []Point {
    39  	// Pass through
    40  	return o.plugin.ReceiveIssue(issue)
    41  }
    42  
    43  // ReceiveIssueEvent is a wrapper on plugin.ReceiveIssueEvent()
    44  func (o *FakeCommentPluginWrapper) ReceiveIssueEvent(event sql.IssueEvent) []Point {
    45  	// Pass through
    46  	return o.plugin.ReceiveIssueEvent(event)
    47  }
    48  
    49  // ReceiveComment creates a fake "commented" event
    50  func (o *FakeCommentPluginWrapper) ReceiveComment(comment sql.Comment) []Point {
    51  	// Create a fake "commented" event for every comment we receive.
    52  	fakeEvent := sql.IssueEvent{
    53  		IssueID:        comment.IssueID,
    54  		Event:          "commented",
    55  		EventCreatedAt: comment.CommentCreatedAt,
    56  		Actor:          &comment.User,
    57  	}
    58  
    59  	return append(
    60  		o.plugin.ReceiveComment(comment),
    61  		o.plugin.ReceiveIssueEvent(fakeEvent)...,
    62  	)
    63  }