 (defn in-progress? [build] (nil? (:result build)))
 
 (defn- get-release-state [release-env previous-release-env]
-    (cond (release-succeeded? release-env) :succeeded
-          (and (release-in-progress? release-env) (release-succeeded? previous-release-env)) :in-progress
-          (and (release-in-progress? release-env) (not (release-succeeded? previous-release-env))) :in-progress-after-failed
-          (release-not-started? release-env) :not-started
-          :default :failed))
+  (cond (release-succeeded? release-env) :succeeded
+        (and (release-in-progress? release-env) (release-succeeded? previous-release-env)) :in-progress
+        (and (release-in-progress? release-env) (not (release-succeeded? previous-release-env))) :in-progress-after-failed
+        (release-not-started? release-env) :not-started
+        :default :failed))
 
 (defn get-state [build previous-build]
   (cond (succeeded? build) :succeeded

        build-definition-ids (map :id build-definitions)]
    (universal-monitor-for-definition-ids vso-api vso-release-api request build-definition-ids release-definition-ids)))

(def routes ["/" {"" :universal-monitor}])

(defn wrap-routes [handlers]
  (fn [request]
    (when-let [route-method (bidi/match-route routes (:uri request))]
      (when-let [handler (-> route-method :handler handlers)]
        (handler (merge request (select-keys route-method [:route-params])))))))

(defn handlers [vso-api vso-release-api]
  {:universal-monitor (partial universal-monitor vso-api vso-release-api)})

(defn -main [& [vso-account vso-project vso-personal-access-token port]]
  (let [port (Integer. (or port 3000))]
    (if (and vso-account vso-project vso-personal-access-token port)
      (let [vso-api (api/vso-api-fns logger
                                     (api/vso-api-get-fn vso-personal-access-token)
                                     vso-account
                                     vso-project)
            vso-release-api (release-api/vso-release-api-fns
                              logger
                              (release-api/vso-release-api-get-fn vso-personal-access-token)
                              vso-account
                              vso-project)
            wrapped-handler (-> (handlers vso-api vso-release-api)
                                wrap-routes
                                (resource/wrap-resource "public")
                                (params/wrap-params))]
        (ring-jetty/run-jetty wrapped-handler {:port port}))
      (println "App didn't start due to missing parameters."))))
