 ; Licensed under the terms of the GNU Affero General Public License v3.
 ; See the "LICENSE.txt" file provided with this software.
 
+
+; TODO key of attachment as name if possible 
+
 (ns cider-ci.builder.tasks
   (:require 
+    [cider-ci.builder.expansion :as expansion]
+    [cider-ci.builder.spec :as spec]
     [cider-ci.builder.task :as task]
-    [cider-ci.builder.spec :as spec]
-    [cider-ci.builder.expansion :as expansion]
+    [cider-ci.builder.util :as util]
     [cider-ci.utils.config-loader :as config-loader]
     [cider-ci.utils.debug :as debug]
     [cider-ci.utils.exception :as exception]

         (map 
           (fn [context]
             (logging/debug {:context context})
             (let [task-defaults (deep-merge inherited-task-defaults
                                             (or (:task_defaults context) 
                                                 {}))
                   script-defaults (deep-merge inherited-script-defaults
                                               (or (:script_defaults context) 
                                                   {}))]
               (build-tasks-for-single-context context 



;### build tasks ##############################################################
(defn build-scripts [task script-defaults]
  (into {} (for [[name-key script] (or (:scripts task) {})]
             (let [final-script  (util/deep-merge script-defaults script)]
               [name-key final-script]))))

(defn build-task [task-spec task-defaults script-defaults name-prefix]
  (let [merged-task (util/deep-merge task-defaults task-spec)]
    ;(logging/debug {:merged-task merged-task})
    (conj merged-task
          {:scripts (build-scripts merged-task script-defaults)
