Refactoring & cleanup

* fix issues found by lein-kibit
This commit is contained in:
Teemu Patja 2017-03-29 10:36:44 +03:00
parent 6bcdfa905a
commit e49ad18fd8
No known key found for this signature in database
GPG Key ID: F5B7035E6580FD4C
15 changed files with 60 additions and 58 deletions

View File

@ -6,7 +6,8 @@
[commiteth.config :refer [env]]
[mount.core :refer [defstate]]
[migratus.core :as migratus]
[mpg.core :as mpg])
[mpg.core :as mpg]
[clojure.string :as str])
(:import org.postgresql.util.PGobject
java.sql.Array
clojure.lang.IPersistentMap
@ -75,7 +76,7 @@
(let [conn (.getConnection stmt)
meta (.getParameterMetaData stmt)
type-name (.getParameterTypeName meta idx)]
(if-let [elem-type (when (= (first type-name) \_) (apply str (rest type-name)))]
(if-let [elem-type (when (= (first type-name) \_) (str/join (rest type-name)))]
(.setObject stmt idx (.createArrayOf conn elem-type (to-array v)))
(.setObject stmt idx (to-pg-json v))))))

View File

@ -20,10 +20,10 @@
(defn get-enabled
"Lists enabled repository id's for a given user-id"
[user-id]
(->>
(mapcat
vals
(jdbc/with-db-connection [con-db *db*]
(db/get-enabled-repositories con-db {:user_id user-id}))
(mapcat vals)))
(db/get-enabled-repositories con-db {:user_id user-id}))))
(defn update-repo
[repo-id updates]

View File

@ -71,7 +71,7 @@
:gas gas})]
(eth-rpc
"personal_sendTransaction"
[(if (not (nil? to))
[(if-not (nil? to)
(merge args {:to to})
args)
(eth-password)])))
@ -143,8 +143,7 @@
(log/debug "address hash" hash "addr" addr)
(->>
(map-indexed (fn [idx _]
(let [hash-ch-int (-> (nth hash idx)
(hex-ch->num))
(let [hash-ch-int (hex-ch->num (nth hash idx))
ch (nth addr idx)
ch-lower (lower-ch ch)
ch-upper (upper-ch ch)]

View File

@ -82,15 +82,15 @@
own login."
[token]
(let [all-repos-with-admin-access
(->>
(filter #(-> % :permissions :admin)
(map #(merge
{:owner-login (get-in % [:owner :login])}
{:owner-type (get-in % [:owner :type])}
{:owner-avatar-url (get-in % [:owner :avatar_url])}
(select-keys % repo-fields))
(repos/repos (merge (auth-params token) {:type "all"
:all-pages true})))
(filter #(-> % :permissions :admin)))]
(repos/repos
(merge (auth-params token) {:type "all"
:all-pages true}))))]
(group-by :owner-login all-repos-with-admin-access)))
(defn get-user

View File

@ -25,5 +25,5 @@
(GET "/" {{user :identity} :session}
(home-page user))
(GET "/logout" {session :session}
(-> (redirect "/")
(assoc :session (dissoc session :identity)))))
(assoc (redirect "/")
:session (dissoc session :identity))))

View File

@ -44,7 +44,7 @@
(response/redirect "/")
(let [admin-token? (str/includes? scope "repo")
token-key (if admin-token? :admin-token :token)
user (-> (get-or-create-user access-token)
(assoc token-key access-token))]
(-> (response/redirect "/")
(assoc :session {:identity user})))))))
user (assoc (get-or-create-user access-token)
token-key access-token)]
(assoc (response/redirect "/")
:session {:identity user}))))))

View File

@ -109,8 +109,9 @@
:let [b (update ob :balance decimal->str)]]
[(:issue_id b)
(conj b
(let [claims (->> (bounties-db/bounty-claims (:issue_id b))
(map #(update % :balance decimal->str)))]
(let [claims (map
#(update % :balance decimal->str)
(bounties-db/bounty-claims (:issue_id b)))]
{:claims claims}))]))))

View File

@ -181,7 +181,7 @@
(mount/defstate scheduler
:start (let [every-minute (rest
(periodic-seq (t/now)
(-> 1 t/minutes)))
(t/minutes 1)))
stop-fn (chime-at every-minute
run-periodic-tasks
{:error-handler (fn [e]

View File

@ -1,9 +1,10 @@
(ns commiteth.util.digest
(:import [javax.crypto]))
(:import [javax.crypto])
(:require [clojure.string :as str]))
;; credit: https://gist.github.com/visibletrap/4571244
(defn hex-hmac-sha1 [key input]
(let [secret (javax.crypto.spec.SecretKeySpec. (. key getBytes "UTF-8") "HmacSHA1")
(let [secret (javax.crypto.spec.SecretKeySpec. (.getBytes key "UTF-8") "HmacSHA1")
hmac-sha1 (doto (javax.crypto.Mac/getInstance "HmacSHA1") (.init secret))
bytes (. hmac-sha1 doFinal (. input getBytes "UTF-8"))]
(apply str (map (partial format "%02x") bytes))))
bytes (.doFinal hmac-sha1 (.getBytes input "UTF-8"))]
(str/join (map (partial format "%02x") bytes))))

View File

@ -26,8 +26,8 @@
(defn gen-comment-image [address balance issue-url]
(let [qr-image (-> (image->base64 (generate-qr-image address))
(String. "ISO-8859-1"))
(let [qr-image (String. (image->base64 (generate-qr-image address))
"ISO-8859-1")
html (:body (render "bounty.html"
{:qr-image qr-image
:balance balance
@ -37,7 +37,7 @@
{out :out err :err exit :exit}
(sh command "-f" "png" "--quality" "80" "--width" "1336" "-" "-"
:out-enc :bytes :in html)]
(if (= 0 exit)
(if (zero? exit)
(do
(log/debug "PNG generated succesfully" out err exit html)
out)

View File

@ -39,7 +39,7 @@
[:div.description
[item-description item]]
[:div.footer-row
(when (not (= item-type "new-bounty"))
(when-not (= item-type "new-bounty")
[:div.balance-badge (str "ETH " balance )])
[:div.time (moment-timestamp updated)]]]])

View File

@ -25,8 +25,7 @@
(defn moment-timestamp [time]
(let [now (.now js/Date.)
js-time (clj->js time)]
(-> (js/moment.utc)
(.to js-time))))
(.to (js/moment.utc) js-time)))
(defn issue-url [owner repo number]
(str "https://github.com/" owner "/" repo "/issues/" number))

View File

@ -119,7 +119,7 @@
(into [:div.ui.items.top-hunters]
(map-indexed (fn [idx hunter]
[:div.item
[:div.leader-ordinal (str (+ 1 idx))]
[:div.leader-ordinal (str (inc idx))]
[:div.ui..mini.circular.image
[:img {:src (:avatar-url hunter)}]]
[:div.content

View File

@ -69,7 +69,7 @@
(defn assoc-in-if-not-empty [m path val]
(if (not (empty? val))
(if (seq val)
(assoc-in m path val)
m))
@ -105,7 +105,7 @@
(if-let [res (and ks (dissoc-in (get m k) ks))]
(assoc m k res)
(let [res (dissoc m k)]
(when-not (empty? res)
(when (seq res)
res)))))
(reg-event-fx
@ -251,10 +251,12 @@
(reg-event-db
:repo-toggle-success
(fn [db [_ repo]]
(assoc db :repos (update-repo-state (:repos db)
(update-in db
[:repos]
update-repo-state
(:full_name repo)
{:busy? false
:enabled (:enabled repo)} ))))
:enabled (:enabled repo)})))
(reg-event-fx
:repo-toggle-error
@ -315,11 +317,10 @@
[issue-id]
(fn [error payout-hash]
(when error
(do
(dispatch [:set-flash-message
:error
(str "Error sending transaction: " error)])
(dispatch [:payout-confirm-failed issue-id])))
(dispatch [:payout-confirm-failed issue-id]))
(when payout-hash
(dispatch [:save-payout-hash issue-id payout-hash]))))

View File

@ -11,7 +11,7 @@
address (r/atom @(rf/subscribe [:get-in [:user :address]]))]
(fn []
(let [web3 (.-web3 js/window)
web3-accounts (into [] (when-not (nil? web3) (-> web3
web3-accounts (vec (when-not (nil? web3) (-> web3
.-eth
.-accounts
js->clj)))]
@ -24,7 +24,7 @@
(if-not (empty? web3-accounts)
[dropdown {:class "address-input"} "Select address"
address
(into []
(vec
(for [acc web3-accounts]
acc))]
[:div.ui.input.address-input