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:
parent
5c004bbb47
commit
4061f0c5b3
|
@ -84,6 +84,12 @@ WHERE user_id = :user_id
|
||||||
AND state = 2;
|
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
|
-- :name update-repo-generic :! :n
|
||||||
/* :require [clojure.string :as string]
|
/* :require [clojure.string :as string]
|
||||||
[hugsql.parameters :refer [identifier-param-quote]] */
|
[hugsql.parameters :refer [identifier-param-quote]] */
|
||||||
|
@ -161,6 +167,12 @@ SET comment_id = :comment_id,
|
||||||
updated = timezone('utc'::text, now())
|
updated = timezone('utc'::text, now())
|
||||||
WHERE issue_id = :issue_id;
|
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 :? :*
|
-- :name list-pending-deployments :? :*
|
||||||
-- :doc retrieves pending transaction ids
|
-- :doc retrieves pending transaction ids
|
||||||
SELECT
|
SELECT
|
||||||
|
|
|
@ -73,3 +73,16 @@
|
||||||
(if png-data
|
(if png-data
|
||||||
(comment-images/save-image! issue-id hash png-data)
|
(comment-images/save-image! issue-id hash png-data)
|
||||||
(log/error "Failed ot generate PNG"))))
|
(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)))))))
|
||||||
|
|
|
@ -19,6 +19,18 @@
|
||||||
(db/update-commit-sha con-db {:issue_id issue-id
|
(db/update-commit-sha con-db {:issue_id issue-id
|
||||||
:commit_sha commit-sha})))
|
: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
|
(defn update-transaction-hash
|
||||||
"Updates issue with transaction-hash"
|
"Updates issue with transaction-hash"
|
||||||
[issue-id transaction-hash]
|
[issue-id transaction-hash]
|
||||||
|
|
|
@ -164,6 +164,13 @@
|
||||||
(merge pr-data {:state :closed
|
(merge pr-data {:state :closed
|
||||||
:commit_sha head-sha}))))))))
|
: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
|
(defn handle-issue
|
||||||
[webhook-payload]
|
[webhook-payload]
|
||||||
|
@ -174,7 +181,9 @@
|
||||||
(when (and
|
(when (and
|
||||||
(= "closed" action)
|
(= "closed" action)
|
||||||
(bounties/has-bounty-label? (:issue webhook-payload)))
|
(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))
|
(ok))
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -206,6 +206,7 @@
|
||||||
(log/error "Scheduled task failed" e)
|
(log/error "Scheduled task failed" e)
|
||||||
(throw e))})]
|
(throw e))})]
|
||||||
(log/info "started scheduler")
|
(log/info "started scheduler")
|
||||||
|
(bounties/update-bounty-issue-titles)
|
||||||
stop-fn)
|
stop-fn)
|
||||||
:stop (do
|
:stop (do
|
||||||
(log/info "stopping scheduler")
|
(log/info "stopping scheduler")
|
||||||
|
|
Loading…
Reference in New Issue