Skip to content
This repository was archived by the owner on Apr 12, 2022. It is now read-only.

Commit

Permalink
Support comma-separated address lists
Browse files Browse the repository at this point in the history
Works around a bug in postal where an invalid address doesn't raise
exception drewr/postal#62.
  • Loading branch information
drewr committed Nov 11, 2015
1 parent c382396 commit e70025d
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 11 deletions.
3 changes: 2 additions & 1 deletion src/runbld/publish.clj
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@
(dissoc (:process opts) :proc)
(:build opts)
{:mail-from (-> opts :email :from)
:rcpt-to (-> opts :email :to)
:rcpt-to (email/maybe-split-addr
(-> opts :email :to))
:github-name (format "%s/%s#%s"
(-> opts :build :org)
(-> opts :build :project)
Expand Down
9 changes: 8 additions & 1 deletion src/runbld/publish/email.clj
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
(ns runbld.publish.email
(:refer-clojure :exclude [send])
(:require [postal.core :as mail]
(:require [clojure.string :as str]
[postal.core :as mail]
[stencil.core :as mustache]))

(defn maybe-split-addr [s]
(if (and (string? s) (.contains s ","))
(->> (str/split s #",")
(map #(.trim %)))
s))

(defn send* [conn from to subject msg]
(mail/send-message
conn
Expand Down
9 changes: 6 additions & 3 deletions test/runbld.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,15 @@ email:
pass: pass!
from: build@example.com
to: user@example.com
template: test/email.mustache
template: test/templates/default.mustache

# will be merged with top-level sections
profiles:
foo-bar-baz:
elastic-proj1-master:
email:
to: foo@example.com
template: test/foo.mustache
template: test/templates/proj1.mustache
elastic-proj2-master:
email:
to: foo@example.com, bar@example.com

4 changes: 2 additions & 2 deletions test/runbld/test/build_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
(build/wrap-merge-profile
identity))
(opts/parse-args ["-c" "test/runbld.yaml"
"--job-name" "foo,bar,baz"
"--job-name" "elastic,proj1,master"
"/path/to/script.bash"]))]
(is (= "test/foo.mustache"
(is (= "test/templates/proj1.mustache"
(-> profiled-opts :email :template)))
(is (= "foo@example.com"
(-> profiled-opts :email :to)))))
19 changes: 15 additions & 4 deletions test/runbld/test/publish_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,22 @@
(deftest email
(let [sent (atom [])]
(with-redefs [email/send* (fn [conn from to subj body]
(swap! sent conj [to body]))
env/facter (fn [& args] {:some :fact})]
(swap! sent conj [to body]))]

(let [opts (opts/parse-args ["-c" "test/runbld.yaml"
"--job-name" "foo,bar,baz"
"--job-name" "elastic,proj1,master"
"test/success.bash"])
res (main/run opts)]
(is (= 0 (count @(:errors res))))
(is (= [["foo@example.com"
"greetings foo-bar-baz!\n"]] @sent))))))
"greetings elastic-proj1-master!\n"]] @sent)))

(swap! sent pop)

(let [opts (opts/parse-args ["-c" "test/runbld.yaml"
"--job-name" "elastic,proj2,master"
"test/success.bash"])
res (main/run opts)]
(is (= 0 (count @(:errors res))))
(is (= [[["foo@example.com" "bar@example.com"]
"in template for elastic-proj2-master\n"]] @sent))))))
1 change: 1 addition & 0 deletions test/templates/default.mustache
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
in template for {{ profile-name }}
File renamed without changes.

0 comments on commit e70025d

Please sign in to comment.