Fix bug in handle-issue-labeled + logging

This commit is contained in:
Teemu Patja 2017-02-19 14:33:02 +02:00
parent 0fef7d931d
commit 7ce1dc6cdc
No known key found for this signature in database
GPG Key ID: F5B7035E6580FD4C
6 changed files with 23 additions and 18 deletions

View File

@ -12,5 +12,3 @@
(defn restart []
(stop)
(start))

View File

@ -22,11 +22,13 @@
issue-title :title} issue
created-issue (issues/create repo-id issue-id issue-number issue-title)
repo-owner-address (:address (users/get-repo-owner repo-id))]
(log/info (format "Issue %s/%s/%s labeled as bounty" login repo issue-number))
(log/debug "Adding bounty for issue " repo issue-number "owner address: " repo-owner-address)
(if (= 1 created-issue)
(let [transaction-hash (eth/deploy-contract repo-owner-address)]
(log/info "Contract deployed, transaction-hash:" transaction-hash )
(issues/update-transaction-hash issue-id transaction-hash))
(do
(log/debug "deploying contract to " repo-owner-address)
(let [transaction-hash (eth/deploy-contract repo-owner-address)]
(log/info "Contract deployed, transaction-hash:" transaction-hash )
(issues/update-transaction-hash issue-id transaction-hash)))
(log/debug "Issue already exists in DB, ignoring"))))

View File

@ -108,6 +108,7 @@
(defn remove-webhook
[full-repo hook-id token]
;; TODO: possible error ignored
(let [[user repo] (str/split full-repo #"/")]
(log/debug "removing webhook" (str user "/" repo) hook-id token)
(repos/delete-hook user repo hook-id (auth-params token))))

View File

@ -82,13 +82,13 @@
(defn wrap-base [handler]
(-> ((:middleware defaults) handler)
wrap-auth
wrap-flash
;; wrap-flash
(wrap-session {:timeout (* 60 60 6)
:cookie-attrs {:http-only true}})
(wrap-defaults
(-> site-defaults
(assoc-in [:security :anti-forgery] false)
(dissoc :session)))
wrap-context
;; wrap-context
wrap-gzip
wrap-internal-error))

View File

@ -41,17 +41,19 @@
(defn handle-issue-labeled
[webhook-payload]
(log/debug "handle-issue-labeled")
(let [{issue :issue} webhook-payload
{repo-id :id
repo-name :name
{login :login} :owner} (:repository webhook-payload)
repo-map {:repo repo-name :login login :repo_id repo-id}]
(bounties/add-bounty-for-issue repo-name repo-id issue)))
(bounties/add-bounty-for-issue repo-name repo-id login issue)))
(defn handle-issue-closed
;; TODO: does not work in case the issue is closed on github web ui
[{{{user :login} :owner repo :name} :repository
{issue-id :id issue-number :number} :issue}]
(log/debug "handle-issue-closed")
(future
(when-let [commit-id (find-commit-id user repo issue-number ["referenced" "closed"])]
(log/debug (format "Issue %s/%s/%s closed with commit %s" user repo issue-number commit-id))
@ -120,21 +122,21 @@
(defn handle-issue
[webhook-payload]
(when-let [action (:action webhook-payload)]
(log/debug "handle-issue")
(log/debug "handle-issue" action)
(when (labeled-as-bounty? action webhook-payload)
(handle-issue-labeled webhook-payload))
(when (and
(= "closed" action)
(bounties/has-bounty-label? (:issue webhook-payload)))
(handle-issue-closed webhook-payload)))
(ok (str webhook-payload)))
(ok))
(defn handle-pull-request
[pull-request]
(when (= "closed" (:action pull-request))
(handle-pull-request-closed pull-request))
(ok (str pull-request)))
(ok))
(defn validate-secret [webhook-payload raw-payload github-signature]
@ -150,7 +152,9 @@
(let [raw-payload (slurp body)
payload (json/parse-string raw-payload true)]
(if (validate-secret payload raw-payload (get headers "x-hub-signature"))
(case (get headers "x-github-event")
"issues" (handle-issue payload)
"pull_request" (handle-pull-request payload)
(ok))))))
(do (log/debug "Github secret validation OK")
(log/debug "x-github-event" (get headers "x-github-event"))
(case (get headers "x-github-event")
"issues" (handle-issue payload)
"pull_request" (handle-pull-request payload)
(ok)))))))

View File

@ -10,8 +10,8 @@
[java.lang.management ManagementFactory]))
(defn update-issue-contract-address
"For each pending deployment:
gets transasction receipt, updates db state and posts github comment"
"For each pending deployment: gets transaction receipt, updates db
state (contract-address, comment-id) and posts github comment"
[]
(doseq [{issue-id :issue_id
transaction-hash :transaction_hash} (issues/list-pending-deployments)]