diff --git a/resources/sql/queries.sql b/resources/sql/queries.sql index e664709..3e0c919 100644 --- a/resources/sql/queries.sql +++ b/resources/sql/queries.sql @@ -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 diff --git a/src/clj/commiteth/bounties.clj b/src/clj/commiteth/bounties.clj index 86d72e7..1057d15 100644 --- a/src/clj/commiteth/bounties.clj +++ b/src/clj/commiteth/bounties.clj @@ -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))))))) diff --git a/src/clj/commiteth/db/issues.clj b/src/clj/commiteth/db/issues.clj index 9a2b777..8eac323 100644 --- a/src/clj/commiteth/db/issues.clj +++ b/src/clj/commiteth/db/issues.clj @@ -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] diff --git a/src/clj/commiteth/routes/webhooks.clj b/src/clj/commiteth/routes/webhooks.clj index f4b69d2..27398e3 100644 --- a/src/clj/commiteth/routes/webhooks.clj +++ b/src/clj/commiteth/routes/webhooks.clj @@ -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)) diff --git a/src/clj/commiteth/scheduler.clj b/src/clj/commiteth/scheduler.clj index b03d08b..c7f2194 100644 --- a/src/clj/commiteth/scheduler.clj +++ b/src/clj/commiteth/scheduler.clj @@ -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")