Add template to report request (#10)

This commit is contained in:
Mariana Cardoso 2018-03-19 13:37:58 -07:00 коммит произвёл Troy Dai
Родитель b1ca93ec6b
Коммит 15d7da0809
2 изменённых файлов: 9 добавлений и 2 удалений

Просмотреть файл

@ -105,7 +105,13 @@ func main() {
} }
owners := string(secret.Data["owners"]) owners := string(secret.Data["owners"])
reportutils.Report(run, strings.Split(owners, ",")) templateURL, ok := secret.Data["email.path.template"]
if ok {
reportutils.Report(run, strings.Split(owners, ","), string(templateURL))
} else {
common.LogWarning("Failed to get the `email.path.template` value from the kubernetes secret. A generic template will be used instead")
reportutils.Report(run, strings.Split(owners, ","), "")
}
run.Status = common.RunStatusCompleted run.Status = common.RunStatusCompleted
run, err = run.SubmitChange() run, err = run.SubmitChange()

Просмотреть файл

@ -15,7 +15,7 @@ import (
var httpClient = &http.Client{} var httpClient = &http.Client{}
// Report method requests the email service to send emails // Report method requests the email service to send emails
func Report(run *models.Run, receivers []string) { func Report(run *models.Run, receivers []string, templateURL string) {
common.LogInfo("Sending report...") common.LogInfo("Sending report...")
remark, ok := run.Settings[common.KeyRemark] remark, ok := run.Settings[common.KeyRemark]
@ -31,6 +31,7 @@ func Report(run *models.Run, receivers []string) {
content := make(map[string]string) content := make(map[string]string)
content["run_id"] = strconv.Itoa(run.ID) content["run_id"] = strconv.Itoa(run.ID)
content["receivers"] = strings.Join(receivers, ",") content["receivers"] = strings.Join(receivers, ",")
content["template"] = templateURL
body, err := json.Marshal(content) body, err := json.Marshal(content)
if err != nil { if err != nil {