github.com/billybanfield/evergreen@v0.0.0-20170525200750-eeee692790f7/notify/build_failure_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 failure notifications. Implements NotificationHandler from
    11  // notification_handler.go.
    12  type BuildFailureHandler struct {
    13  	BuildNotificationHandler
    14  	Name string
    15  }
    16  
    17  func (self *BuildFailureHandler) GetNotifications(ae *web.App, key *NotificationKey) ([]Email, error) {
    18  	var emails []Email
    19  	preface := mciFailurePreface
    20  	if key.NotificationRequester == evergreen.PatchVersionRequester {
    21  		preface = patchFailurePreface
    22  	}
    23  
    24  	triggeredNotifications, err := self.getRecentlyFinishedBuildsWithStatus(key,
    25  		evergreen.BuildFailed, preface, failureSubject)
    26  
    27  	if err != nil {
    28  		return nil, err
    29  	}
    30  
    31  	for _, triggered := range triggeredNotifications {
    32  		email, err := self.TemplateNotification(ae, &triggered)
    33  		if err != nil {
    34  			grip.Noticef("template error with build failure notification for '%s': %s",
    35  				triggered.Current.Id, err.Error())
    36  			continue
    37  		}
    38  
    39  		emails = append(emails, email)
    40  	}
    41  
    42  	return emails, nil
    43  }
    44  
    45  func (self *BuildFailureHandler) TemplateNotification(ae *web.App, notification *TriggeredBuildNotification) (Email, error) {
    46  	changeInfo, err := self.GetChangeInfo(notification)
    47  	if err != nil {
    48  		return nil, err
    49  	}
    50  	return self.templateNotification(ae, notification, changeInfo)
    51  }
    52  
    53  func (self *BuildFailureHandler) GetChangeInfo(
    54  	notification *TriggeredBuildNotification) ([]ChangeInfo, error) {
    55  	return self.constructChangeInfo([]build.Build{*notification.Current}, &notification.Key)
    56  }