Skip to content

Commit

Permalink
feat(api): allow variable interpolation in notification recipients (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
fsamin authored Sep 21, 2021
1 parent d164d19 commit 9f81302
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 1 deletion.
13 changes: 12 additions & 1 deletion engine/api/notification/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package notification
import (
"context"
"fmt"
"strings"

"github.com/go-gorp/gorp"
"github.com/rockbears/log"
Expand Down Expand Up @@ -217,7 +218,17 @@ func getWorkflowEvent(notif *sdk.UserNotificationSettings, params map[string]str
Subject: subject,
Body: body,
}
e.Recipients = append(e.Recipients, notif.Recipients...)

var recipients []string
for i := range notif.Recipients {
r, err := interpolate.Do(notif.Recipients[i], params)
if err != nil {
return sdk.EventNotif{}, err
}
recipients = append(recipients, strings.Split(r, ",")...)
}

e.Recipients = append(e.Recipients, recipients...)

return e, nil
}
Expand Down
17 changes: 17 additions & 0 deletions tests/04_sc_workflow_run_notif.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ testcases:
- script: "{{.cdsctl}} -f {{.cdsctl.config}} project remove --force 04SCWORKFLOWRUNNOTIF"
- script: "{{.cdsctl}} -f {{.cdsctl.config}} group remove --force 04scworkflowrunnotif"
- script: "{{.cdsctl}} -f {{.cdsctl.config}} project add 04SCWORKFLOWRUNNOTIF 04SCWorkflowRunNotif"
- script: "{{.cdsctl}} -f {{.cdsctl.config}} project variable add 04SCWORKFLOWRUNNOTIF email_notif string \"[email protected],[email protected]\""

- name: import pipeline and workflow
steps:
Expand Down Expand Up @@ -69,6 +70,22 @@ testcases:
verify:
from: result.bodyjson.content-decoded
regex: logcontent:foo2
- type: http
method: GET
url: '{{.smtpmock.url}}/messages/[email protected]'
assertions:
- result.statuscode ShouldEqual 200
- result.bodyjson.__len__ ShouldEqual 1
retry: 10
delay: 3
- type: http
method: GET
url: '{{.smtpmock.url}}/messages/[email protected]'
assertions:
- result.statuscode ShouldEqual 200
- result.bodyjson.__len__ ShouldEqual 1
retry: 10
delay: 3

- name: run workflow 04SCWorkflowRunNotif-WORKFLOW-EMPTY
steps:
Expand Down
1 change: 1 addition & 0 deletions tests/fixtures/04SCWorkflowRunNotif/workflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ notifications:
on_success: always
recipients:
- [email protected]
- "{{.cds.proj.email_notif}}"
template:
body: |
title:{{.cds.project}}/{{.cds.workflow}}#{{.cds.version}} {{.cds.status}}
Expand Down

0 comments on commit 9f81302

Please sign in to comment.