Skip to content

Commit

Permalink
fix(api): interpolate notif event (#5076)
Browse files Browse the repository at this point in the history
  • Loading branch information
yesnault authored Mar 24, 2020
1 parent e731af3 commit 064f428
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 11 deletions.
9 changes: 4 additions & 5 deletions engine/api/notification/mail.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,13 @@ import (

var regexpIsHTML = regexp.MustCompile(`^\w*\n*<[a-z][\s\S]*>`)

// SendMailNotif Send user notification by mail
func SendMailNotif(ctx context.Context, notif sdk.EventNotif) {
log.Info(ctx, "notification.SendMailNotif> Send notif '%s'", notif.Subject)
errors := []string{}
// sendMailNotif Send user notification by mail
func sendMailNotif(ctx context.Context, notif sdk.EventNotif) {
log.Info(ctx, "notification.sendMailNotif> Send notif '%s' nb.Recipients:%d", notif.Subject, len(notif.Recipients))
for _, recipient := range notif.Recipients {
isHTML := regexpIsHTML.MatchString(notif.Body)
if err := mail.SendEmail(ctx, notif.Subject, bytes.NewBufferString(notif.Body), recipient, isHTML); err != nil {
errors = append(errors, err.Error())
log.Error(ctx, "sendMailNotif>error while sending mail: %v", err.Error())
}
}
}
6 changes: 2 additions & 4 deletions engine/api/notification/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ func GetUserWorkflowEvents(ctx context.Context, db gorp.SqlExecutor, store cache
if err != nil {
log.Error(ctx, "notification.GetUserWorkflowEvents> unable to handle event %+v: %v", jn, err)
}
go SendMailNotif(ctx, notif)
go sendMailNotif(ctx, notif)
}
}
}
Expand Down Expand Up @@ -208,9 +208,7 @@ func getWorkflowEvent(notif *sdk.UserNotificationSettings, params map[string]str
Subject: subject,
Body: body,
}
for _, r := range notif.Recipients {
e.Recipients = append(e.Recipients, r)
}
e.Recipients = append(e.Recipients, notif.Recipients...)

return e, nil
}
Expand Down
3 changes: 3 additions & 0 deletions engine/api/repositoriesmanager/dao.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,9 @@ func UpdateForProject(db gorp.SqlExecutor, proj *sdk.Project, vcsServers []sdk.P
//DeleteForProject unlink a project with a repository manager
func DeleteForProject(db gorp.SqlExecutor, proj *sdk.Project, vcsServer *sdk.ProjectVCSServer) error {
servers, err := LoadAllForProject(db, proj.Key)
if err != nil {
return err
}
for i := range servers {
if servers[i].Name == vcsServer.Name {
servers = append(servers[:i], servers[i+1:]...)
Expand Down
2 changes: 1 addition & 1 deletion engine/api/workermodel/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ var (
//Status returns info about worker Model Status
func Status(db *gorp.DbMap) sdk.MonitoringStatusLine {
status := sdk.MonitoringStatusOK
if time.Now().Sub(lastRequest) > 2*time.Second {
if time.Since(lastRequest) > 2*time.Second {
queryCount := `select count(worker_model.id) from worker_model where nb_spawn_err > 0`

count, errc := db.SelectInt(queryCount)
Expand Down
2 changes: 1 addition & 1 deletion engine/api/workflow_event.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func WorkflowSendEvent(ctx context.Context, db gorp.SqlExecutor, store cache.Sto
}

nr, err := workflow.LoadNodeRunByID(db, wnr.ID, workflow.LoadRunOptions{
DisableDetailledNodeRun: true,
DisableDetailledNodeRun: false, // load build parameters, used in notif interpolate below
})
if err != nil {
log.Warning(ctx, "workflowSendEvent > Cannot load workflow node run: %v", err)
Expand Down

0 comments on commit 064f428

Please sign in to comment.