Skip to content

Commit

Permalink
init repos when syncing client to server fails
Browse files Browse the repository at this point in the history
Partially addresses #6
  • Loading branch information
Heliosmaster committed May 17, 2019
1 parent 5727796 commit 257a3e4
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 10 deletions.
7 changes: 3 additions & 4 deletions src/flow_bot/core.clj
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
(ns flow-bot.core
(:require
[clojure.core.async :as async]
[clojure.java.shell :as sh]
[clojure.tools.logging :as log]
[compojure.core :refer [defroutes GET PUT POST DELETE routes]]
[environ.core :refer [env]]
[flow-bot.event :as event]
[flow-bot.util :as util]
[mount.core :as mount]
[ring.adapter.jetty :as jetty]
[ring.middleware.json :refer [wrap-json-body]]
Expand Down Expand Up @@ -39,12 +39,11 @@
(-> (routes handler)
(wrap-json-body {:keywords? true})))

(defn init-repos! []
(log/info (sh/sh "sh" "-c" (format "./init-repos.sh %s %s %s %s" (env :server-repo) (env :server-git) (env :client-repo) (env :client-git)))))


(mount/defstate repos
:start (do (log/info "Initializing repos")
(init-repos!)))
(util/init-repos!)))

(mount/defstate server
:start (do (log/info "Starting server")
Expand Down
13 changes: 7 additions & 6 deletions src/flow_bot/event.clj
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@
(:require
[clojure.java.shell :as sh]
[clojure.string :as str]
[environ.core :refer [env]]
[clojure.tools.logging :as log]
[tentacles.issues :as issues]
[environ.core :refer [env]]
[flow-bot.util :as util]
[tentacles.data :as git]
[tentacles.issues :as issues]
[tentacles.orgs :as orgs]
[tentacles.pulls :as pulls]
[tentacles.repos :as repos]
[clojure.string :as string]))
[tentacles.repos :as repos]))

(defonce app-state (atom {:authors {}}))

Expand Down Expand Up @@ -78,7 +78,7 @@
author-name (or (:name original-author) (:name commit-author))
author-email (or (:email original-author) (:email commit-author))
message (get-in event [:head_commit :message])
sanitized-message (string/trim (string/replace message #"\(#\d+\)" ""))]
sanitized-message (str/trim (str/replace message #"\(#\d+\)" ""))]
(log/info (format "Merging commit '%s' <%s> from %s <%s>" sanitized-message head-commit-sha author-name author-email))
(log/info (sh/sh "sh" "-c" (format "./sync-client.sh %s %s %s '%s' '%s' %s"
(env :server-repo)
Expand Down Expand Up @@ -116,7 +116,8 @@
(if (= "open" (:state result))
(log/info "PR on server created succesfully")
(log/error "Error when creating server PR"))))
(log/error "ERROR WHEN SYNCING CLIENT TO SERVER"))))))
(do (log/error "ERROR WHEN SYNCING CLIENT TO SERVER")
(util/init-repos!)))))))

(defmethod handle-event! "pull_request" [event]
(let [pr-branch (get-in event [:pull_request :head :ref])
Expand Down
12 changes: 12 additions & 0 deletions src/flow_bot/util.clj
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
(ns flow-bot.util
(:require
[clojure.java.shell :as sh]
[clojure.tools.logging :as log]
[environ.core :refer [env]]))

(defn init-repos! []
(log/info (sh/sh "sh" "-c" (format "./init-repos.sh %s %s %s %s"
(env :server-repo)
(env :server-git)
(env :client-repo)
(env :client-git)))))

0 comments on commit 257a3e4

Please sign in to comment.