From 257a3e4a3fa74654505f24572b1f762f523bc6fa Mon Sep 17 00:00:00 2001 From: Davide Taviani Date: Fri, 17 May 2019 12:00:03 +0300 Subject: [PATCH] init repos when syncing client to server fails Partially addresses #6 --- src/flow_bot/core.clj | 7 +++---- src/flow_bot/event.clj | 13 +++++++------ src/flow_bot/util.clj | 12 ++++++++++++ 3 files changed, 22 insertions(+), 10 deletions(-) create mode 100644 src/flow_bot/util.clj diff --git a/src/flow_bot/core.clj b/src/flow_bot/core.clj index af9f955..133b71f 100644 --- a/src/flow_bot/core.clj +++ b/src/flow_bot/core.clj @@ -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]] @@ -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") diff --git a/src/flow_bot/event.clj b/src/flow_bot/event.clj index f0c4b28..168167a 100644 --- a/src/flow_bot/event.clj +++ b/src/flow_bot/event.clj @@ -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 {}})) @@ -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) @@ -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]) diff --git a/src/flow_bot/util.clj b/src/flow_bot/util.clj new file mode 100644 index 0000000..f246e7e --- /dev/null +++ b/src/flow_bot/util.clj @@ -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)))))