github.com/justinjmoses/evergreen@v0.0.0-20170530173719-1d50e381ff0d/notify/build_completion_handler.go (about)

     1  package notify
     2  
     3  import (
     4  	"github.com/evergreen-ci/evergreen"
     5  	"github.com/evergreen-ci/evergreen/model/build"
     6  	"github.com/evergreen-ci/evergreen/web"
     7  	"github.com/mongodb/grip"
     8  )
     9  
    10  // Handler for build completion notifications, i.e. send notifications whenever
    11  // a build finishes. Implements NotificationHandler from
    12  // notification_handler.go.
    13  type BuildCompletionHandler struct {
    14  	BuildNotificationHandler
    15  	Name string
    16  }
    17  
    18  func (self *BuildCompletionHandler) GetNotifications(ae *web.App, key *NotificationKey) ([]Email, error) {
    19  	var emails []Email
    20  	preface := mciCompletionPreface
    21  	if key.NotificationRequester == evergreen.PatchVersionRequester {
    22  		preface = patchCompletionPreface
    23  	}
    24  	triggeredNotifications, err :=
    25  		self.getRecentlyFinishedBuildsWithStatus(key, "", preface, completionSubject)
    26  	if err != nil {
    27  		return nil, err
    28  	}
    29  
    30  	for _, triggered := range triggeredNotifications {
    31  		email, err := self.TemplateNotification(ae, &triggered)
    32  		if err != nil {
    33  			grip.Noticef("template error with build completion notification for '%s': %s",
    34  				triggered.Current.Id, err.Error())
    35  			continue
    36  		}
    37  
    38  		emails = append(emails, email)
    39  	}
    40  
    41  	return emails, nil
    42  }
    43  
    44  func (self *BuildCompletionHandler) TemplateNotification(ae *web.App, notification *TriggeredBuildNotification) (Email, error) {
    45  	changeInfo, err := self.GetChangeInfo(notification)
    46  	if err != nil {
    47  		return nil, err
    48  	}
    49  	return self.templateNotification(ae, notification, changeInfo)
    50  }
    51  
    52  func (self *BuildCompletionHandler) GetChangeInfo(
    53  	notification *TriggeredBuildNotification) ([]ChangeInfo, error) {
    54  	return self.constructChangeInfo([]build.Build{*notification.Current}, &notification.Key)
    55  }