Introduce maybe-add-bounty-for-issue to limit max added

This commit is contained in:
Oskar Thorén 2017-10-31 12:05:41 -05:00
parent 6cdcf3bfa0
commit ee096a6ceb
4 changed files with 21 additions and 2 deletions

View File

@ -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]

View File

@ -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]

View File

@ -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*]

View File

@ -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