diff --git a/resources/sql/queries.sql b/resources/sql/queries.sql index 9b800b7..6b82a69 100644 --- a/resources/sql/queries.sql +++ b/resources/sql/queries.sql @@ -89,6 +89,10 @@ SELECT i.title, i.issue_number, r.repo, r.owner FROM issues i, repositories r WHERE i.repo_id = r.repo_id; +-- :name get-issues-count :? :1 +SELECT COUNT(*) +FROM issues i, repositories r +WHERE i.repo_id = :repo_id; -- :name update-repo-generic :! :n /* :require [clojure.string :as string] diff --git a/src/clj/commiteth/bounties.clj b/src/clj/commiteth/bounties.clj index ad5cd61..98a4347 100644 --- a/src/clj/commiteth/bounties.clj +++ b/src/clj/commiteth/bounties.clj @@ -17,6 +17,16 @@ (let [labels (:labels issue)] (some #(= label-name (:name %)) labels))) +;; TODO: Change max-limit, also defined in two places +(defn maybe-add-bounty-for-issue [repo repo-id issue] + (let [res (issues/get-issues-count repo-id) + {issues-count :count} res + max-limit + limit-reacted? (> issues-count max-limit) + _ log/debug ("*** get-issues-count" repo-id res count limit-reached?)] + (if limit-reached? + (log/debug "Total issues for repo limit reached " repo issues-count) + (add-bounty-for-issue repo repo-id issue)))) (defn add-bounty-for-issue [repo repo-id issue] (let [{issue-id :id @@ -62,7 +72,7 @@ (log/debug (str "adding bounties for" (count bounty-issues) " existing issues (total " (count bounty-issues) ")")) (doall - (map (partial add-bounty-for-issue repo repo-id) max-bounties)))) + (map (partial maybe-add-bounty-for-issue repo repo-id) max-bounties)))) (defn update-bounty-comment-image [issue-id owner repo issue-number contract-address eth-balance eth-balance-str tokens] diff --git a/src/clj/commiteth/db/issues.clj b/src/clj/commiteth/db/issues.clj index ac59552..834684f 100644 --- a/src/clj/commiteth/db/issues.clj +++ b/src/clj/commiteth/db/issues.clj @@ -24,6 +24,11 @@ (jdbc/with-db-connection [con-db *db*] (db/get-issue-titles con-db {}))) +(defn get-issues-count + [repo-id] + (jdbc/with-db-connection [con-db *db*] + (db/get-issues-count con-db {:repo_id repo-id}))) + (defn update-issue-title [issue-id title] (jdbc/with-db-connection [con-db *db*] diff --git a/src/clj/commiteth/routes/webhooks.clj b/src/clj/commiteth/routes/webhooks.clj index df44a64..baa3046 100644 --- a/src/clj/commiteth/routes/webhooks.clj +++ b/src/clj/commiteth/routes/webhooks.clj @@ -47,7 +47,7 @@ (let [{issue :issue} webhook-payload {repo-id :id repo-name :name} (:repository webhook-payload)] - (bounties/add-bounty-for-issue repo-name repo-id issue))) + (bounties/maybe-add-bounty-for-issue repo-name repo-id issue))) (defn handle-issue-closed [{{{owner :login} :owner repo :name} :repository