github.com/munnerz/test-infra@v0.0.0-20190108210205-ce3d181dc989/prow/github/reporter/reporter.go (about)

     1  /*
     2  Copyright 2018 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 reporter implements a reporter interface for github
    18  // TODO(krzyzacy): move logic from report.go here
    19  package reporter
    20  
    21  import (
    22  	"k8s.io/test-infra/prow/apis/prowjobs/v1"
    23  	"k8s.io/test-infra/prow/config"
    24  	"k8s.io/test-infra/prow/report"
    25  )
    26  
    27  type configAgent interface {
    28  	Config() *config.Config
    29  }
    30  
    31  // Client is a github reporter client
    32  type Client struct {
    33  	gc report.GithubClient
    34  	ca configAgent
    35  }
    36  
    37  // NewReporter returns a reporter client
    38  func NewReporter(gc report.GithubClient, ca configAgent) *Client {
    39  	return &Client{
    40  		gc: gc,
    41  		ca: ca,
    42  	}
    43  }
    44  
    45  // GetName returns the name of the reporter
    46  func (c *Client) GetName() string {
    47  	return "github-reporter"
    48  }
    49  
    50  // ShouldReport returns if this prowjob should be reported by the github reporter
    51  func (c *Client) ShouldReport(pj *v1.ProwJob) bool {
    52  
    53  	if !pj.Spec.Report || pj.Spec.Type != v1.PresubmitJob {
    54  		// Only report presubmit github jobs for github reporter
    55  		return false
    56  	}
    57  
    58  	return true
    59  }
    60  
    61  // Report will report via reportlib
    62  func (c *Client) Report(pj *v1.ProwJob) error {
    63  	// TODO(krzyzacy): ditch ReportTemplate, and we can drop reference to configAgent
    64  	return report.Report(c.gc, c.ca.Config().Plank.ReportTemplate, *pj)
    65  }