                       (sql/from :jobs)
                       (sql/merge-where [:= :tree_id tree-id])
                       (sql/merge-where [:= :key (:job_key trigger)])
-                      (sql/merge-where [:in :state (:states trigger)])
+                      (sql/merge-where [:in :state (or (:states trigger) ["passed"])])
                       (sql/limit 1)) sql/format) ]
     (logging/debug query)
     (->> query

    [cider-ci.builder.issues :refer [create-issue]]

    [cider-ci.utils.core :refer [deep-merge]]
    [cider-ci.utils.http :as http]
    [cider-ci.utils.include-exclude :as include-exclude]
    [cider-ci.utils.jdbc :refer [insert-or-update]]
    [cider-ci.utils.map :refer [convert-to-array]]
    [cider-ci.utils.messaging :as messaging]
    [cider-ci.utils.rdbms :as rdbms]

    [clj-yaml.core :as yaml]

         first
         boolean)))

(defn- branches-for-tree-id [tree-id]
  (->> (-> (sql/select :name :repository_id)
           (sql/from :branches)
           (sql/merge-join
             :commits
             [:= :branches.current_commit_id :commits.id])
           (sql/where [:= :commits.tree_id tree-id])
           sql/format)
       (jdbc/query (rdbms/get-ds))))

(defn- branch-trigger-fulfilled? [tree-id job trigger]
  (boolean
    (when-let [branches (-> tree-id branches-for-tree-id seq)]
      (let [repository (->> (-> (sql/select :branch_trigger_include_match
                                            :branch_trigger_exclude_match)
                                (sql/from :repositories)
                                (sql/merge-where [:in :id (map :repository_id branches)])
                                (sql/format))
                            (jdbc/query (rdbms/get-ds)) first)
            branch-names (map :name branches)]
        (->> branch-names
             (include-exclude/filter
               (:include_match trigger)
               (:exclude_match trigger))
             (include-exclude/filter
               (:branch_trigger_include_match repository)
               (:branch_trigger_exclude_match repository))
             first)))))

(defn trigger-fulfilled? [tree-id job trigger]
  (case (:type trigger)
