Keep bounty issue titles up-to-date with github

* update changed bounty issue titles at startup
* update changed issue title in issue edited webhook handler

Fixes: #67
This commit is contained in:
Teemu Patja 2017-06-13 10:02:58 +03:00
parent 5c004bbb47
commit 4061f0c5b3
No known key found for this signature in database
GPG Key ID: F5B7035E6580FD4C
5 changed files with 48 additions and 1 deletions

View File

@ -84,6 +84,12 @@ WHERE user_id = :user_id
AND state = 2;
-- :name get-issue-titles :? :*
SELECT i.title, i.issue_number, r.repo, r.owner
FROM issues i, repositories r
WHERE i.repo_id = r.repo_id;
-- :name update-repo-generic :! :n
/* :require [clojure.string :as string]
[hugsql.parameters :refer [identifier-param-quote]] */
@ -161,6 +167,12 @@ SET comment_id = :comment_id,
updated = timezone('utc'::text, now())
WHERE issue_id = :issue_id;
-- :name update-issue-title :! :n
-- :doc updates title for a given issue-id
UPDATE issues
SET title = :title
WHERE issue_id = :issue_id;
-- :name list-pending-deployments :? :*
-- :doc retrieves pending transaction ids
SELECT

View File

@ -73,3 +73,16 @@
(if png-data
(comment-images/save-image! issue-id hash png-data)
(log/error "Failed ot generate PNG"))))
(defn update-bounty-issue-titles
"Update stored titles for bounty issues if changed on Github side"
[]
(log/debug "update-bounty-issue-titles")
(for [{:keys [title issue_number repo owner]}
(issues/get-issue-titles)]
(let [gh-issue (github/get-issue owner repo issue_number)]
(if-not (= title (:title gh-issue))
(do
(log/info "Updating changed title for issue" (:id gh-issue))
(issues/update-issue-title (:id gh-issue) (:title gh-issue)))))))

View File

@ -19,6 +19,18 @@
(db/update-commit-sha con-db {:issue_id issue-id
:commit_sha commit-sha})))
(defn get-issue-titles
[]
(jdbc/with-db-connection [con-db *db*]
(db/get-issue-titles con-db {})))
(defn update-issue-title
[issue-id title]
(jdbc/with-db-connection [con-db *db*]
(db/update-issue-title con-db {:issue_id issue-id
:title title})))
(defn update-transaction-hash
"Updates issue with transaction-hash"
[issue-id transaction-hash]

View File

@ -164,6 +164,13 @@
(merge pr-data {:state :closed
:commit_sha head-sha}))))))))
(defn handle-issue-edited
[webhook-payload]
(let [gh-issue (:issue webhook-payload)
issue-id (:id gh-issue)
new-title (:title gh-issue)]
(issues/update-issue-title issue-id new-title)))
(defn handle-issue
[webhook-payload]
@ -174,7 +181,9 @@
(when (and
(= "closed" action)
(bounties/has-bounty-label? (:issue webhook-payload)))
(handle-issue-closed webhook-payload)))
(handle-issue-closed webhook-payload))
(when (= "edited" action)
(handle-issue-edited webhook-payload)))
(ok))

View File

@ -206,6 +206,7 @@
(log/error "Scheduled task failed" e)
(throw e))})]
(log/info "started scheduler")
(bounties/update-bounty-issue-titles)
stop-fn)
:stop (do
(log/info "stopping scheduler")