Skip to content

Commit 064f428

Browse files
authored
fix(api): interpolate notif event (#5076)
1 parent e731af3 commit 064f428

File tree

5 files changed

+11
-11
lines changed

5 files changed

+11
-11
lines changed

engine/api/notification/mail.go

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,13 @@ import (
1212

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

15-
// SendMailNotif Send user notification by mail
16-
func SendMailNotif(ctx context.Context, notif sdk.EventNotif) {
17-
log.Info(ctx, "notification.SendMailNotif> Send notif '%s'", notif.Subject)
18-
errors := []string{}
15+
// sendMailNotif Send user notification by mail
16+
func sendMailNotif(ctx context.Context, notif sdk.EventNotif) {
17+
log.Info(ctx, "notification.sendMailNotif> Send notif '%s' nb.Recipients:%d", notif.Subject, len(notif.Recipients))
1918
for _, recipient := range notif.Recipients {
2019
isHTML := regexpIsHTML.MatchString(notif.Body)
2120
if err := mail.SendEmail(ctx, notif.Subject, bytes.NewBufferString(notif.Body), recipient, isHTML); err != nil {
22-
errors = append(errors, err.Error())
21+
log.Error(ctx, "sendMailNotif>error while sending mail: %v", err.Error())
2322
}
2423
}
2524
}

engine/api/notification/user.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ func GetUserWorkflowEvents(ctx context.Context, db gorp.SqlExecutor, store cache
120120
if err != nil {
121121
log.Error(ctx, "notification.GetUserWorkflowEvents> unable to handle event %+v: %v", jn, err)
122122
}
123-
go SendMailNotif(ctx, notif)
123+
go sendMailNotif(ctx, notif)
124124
}
125125
}
126126
}
@@ -208,9 +208,7 @@ func getWorkflowEvent(notif *sdk.UserNotificationSettings, params map[string]str
208208
Subject: subject,
209209
Body: body,
210210
}
211-
for _, r := range notif.Recipients {
212-
e.Recipients = append(e.Recipients, r)
213-
}
211+
e.Recipients = append(e.Recipients, notif.Recipients...)
214212

215213
return e, nil
216214
}

engine/api/repositoriesmanager/dao.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,9 @@ func UpdateForProject(db gorp.SqlExecutor, proj *sdk.Project, vcsServers []sdk.P
7272
//DeleteForProject unlink a project with a repository manager
7373
func DeleteForProject(db gorp.SqlExecutor, proj *sdk.Project, vcsServer *sdk.ProjectVCSServer) error {
7474
servers, err := LoadAllForProject(db, proj.Key)
75+
if err != nil {
76+
return err
77+
}
7578
for i := range servers {
7679
if servers[i].Name == vcsServer.Name {
7780
servers = append(servers[:i], servers[i+1:]...)

engine/api/workermodel/status.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ var (
1919
//Status returns info about worker Model Status
2020
func Status(db *gorp.DbMap) sdk.MonitoringStatusLine {
2121
status := sdk.MonitoringStatusOK
22-
if time.Now().Sub(lastRequest) > 2*time.Second {
22+
if time.Since(lastRequest) > 2*time.Second {
2323
queryCount := `select count(worker_model.id) from worker_model where nb_spawn_err > 0`
2424

2525
count, errc := db.SelectInt(queryCount)

engine/api/workflow_event.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ func WorkflowSendEvent(ctx context.Context, db gorp.SqlExecutor, store cache.Sto
4141
}
4242

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

0 commit comments

Comments
 (0)