diff --git a/src/runbld/publish.clj b/src/runbld/publish.clj index 747abc3..4f3ea79 100644 --- a/src/runbld/publish.clj +++ b/src/runbld/publish.clj @@ -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) diff --git a/src/runbld/publish/email.clj b/src/runbld/publish/email.clj index 37037fb..17c209a 100644 --- a/src/runbld/publish/email.clj +++ b/src/runbld/publish/email.clj @@ -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 diff --git a/test/runbld.yaml b/test/runbld.yaml index 4a246a4..45a3d5c 100644 --- a/test/runbld.yaml +++ b/test/runbld.yaml @@ -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 diff --git a/test/runbld/test/build_test.clj b/test/runbld/test/build_test.clj index 2128747..0da3be5 100644 --- a/test/runbld/test/build_test.clj +++ b/test/runbld/test/build_test.clj @@ -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))))) diff --git a/test/runbld/test/publish_test.clj b/test/runbld/test/publish_test.clj index 6669518..dea10c3 100644 --- a/test/runbld/test/publish_test.clj +++ b/test/runbld/test/publish_test.clj @@ -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)))))) diff --git a/test/templates/default.mustache b/test/templates/default.mustache new file mode 100644 index 0000000..e329bd2 --- /dev/null +++ b/test/templates/default.mustache @@ -0,0 +1 @@ +in template for {{ profile-name }} diff --git a/test/foo.mustache b/test/templates/proj1.mustache similarity index 100% rename from test/foo.mustache rename to test/templates/proj1.mustache