From 9d9ebefc301096fc475d2f122685e8d3e979d937 Mon Sep 17 00:00:00 2001 From: Vitaliy Vlasov Date: Thu, 1 Mar 2018 16:55:44 +0200 Subject: [PATCH 1/4] [Fix #330] Do not handle claims for issues that have been merged already --- resources/sql/queries.sql | 8 ++++ src/clj/commiteth/db/issues.clj | 6 +++ src/clj/commiteth/routes/webhooks.clj | 64 ++++++++++++--------------- 3 files changed, 42 insertions(+), 36 deletions(-) diff --git a/resources/sql/queries.sql b/resources/sql/queries.sql index 1421ced..0673ca6 100644 --- a/resources/sql/queries.sql +++ b/resources/sql/queries.sql @@ -412,6 +412,14 @@ SELECT exists(SELECT 1 FROM issues WHERE issue_id = :issue_id); +-- :name get-issue :? :1 +-- :doc get issue from DB by repo-id and issue-number +SELECT issue_id, issue_number, is_open, winner_login, commit_sha +FROM issues +WHERE repo_id = :repo_id +AND issue_number = :issue_number; + + -- :name open-bounties :? :* -- :doc all open bounty issues diff --git a/src/clj/commiteth/db/issues.clj b/src/clj/commiteth/db/issues.clj index 834684f..a32634a 100644 --- a/src/clj/commiteth/db/issues.clj +++ b/src/clj/commiteth/db/issues.clj @@ -101,3 +101,9 @@ first :exists boolean))) + +(defn get-issue + [repo-id issue-number] + (jdbc/with-db-connection [con-db *db*] + (db/get-issue con-db {:repo_id repo-id + :issue_number issue-number}))) diff --git a/src/clj/commiteth/routes/webhooks.clj b/src/clj/commiteth/routes/webhooks.clj index 32997e1..8ab27bc 100644 --- a/src/clj/commiteth/routes/webhooks.clj +++ b/src/clj/commiteth/routes/webhooks.clj @@ -109,26 +109,17 @@ (extract pr-title)))) -(defn ensure-bounty-issue - "Checks if an issue has a bounty label attached and returns its number" - [user repo issue-number] - (when-let [issue (github/get-issue user repo issue-number)] - (when (bounties/has-bounty-label? issue) - issue-number))) - - (defn handle-claim - [user-id login name avatar_url owner repo repo-id bounty-issue-number pr-id pr-number head-sha merged? event-type] + [issue user-id login name avatar_url owner repo repo-id pr-id pr-number head-sha merged? event-type] (users/create-user user-id login name nil avatar_url) - (let [issue (github/get-issue owner repo bounty-issue-number) - open-or-edit? (contains? #{:opened :edited} event-type) + (let [open-or-edit? (contains? #{:opened :edited} event-type) close? (= :closed event-type) pr-data {:repo_id repo-id :pr_id pr-id :pr_number pr-number :user_id user-id - :issue_number bounty-issue-number - :issue_id (:id issue) + :issue_number (:issue_number issue) + :issue_id (:issue_id issue) :state event-type}] ;; TODO: in the opened case if the submitting user has no @@ -138,18 +129,18 @@ (cond open-or-edit? (do (log/info "PR with reference to bounty issue" - bounty-issue-number "opened") + (:issue_number issue) "opened") (pull-requests/save (merge pr-data {:state :opened :commit_sha head-sha}))) close? (if merged? (do (log/info "PR with reference to bounty issue" - bounty-issue-number "merged") + (:issue_number issue) "merged") (pull-requests/save (merge pr-data {:state :merged :commit_sha head-sha})) - (issues/update-commit-sha (:id issue) head-sha)) + (issues/update-commit-sha (:issue_id issue) head-sha)) (do (log/info "PR with reference to bounty issue" - bounty-issue-number "closed with no merge") + (:issue_number issue) "closed with no merge") (pull-requests/save (merge pr-data {:state :closed :commit_sha head-sha}))))))) @@ -177,26 +168,27 @@ pr-number :number pr-body :body pr-title :title} :pull_request}] - (log/debug "handle-pull-request-event" event-type owner repo repo-id login pr-body pr-title) - (log/debug (extract-issue-number pr-body pr-title)) - (if-let [bounty-issue-number (->> - (extract-issue-number pr-body pr-title) - (first) - (ensure-bounty-issue owner repo))] - (do - (log/debug "Referenced bounty issue found" owner repo bounty-issue-number) - (handle-claim user-id - login name - avatar_url - owner repo - repo-id - bounty-issue-number - pr-id - pr-number - head-sha - merged? - event-type)) + (log/info "handle-pull-request-event" event-type owner repo repo-id login pr-body pr-title) + (if-let [issue (some->> (extract-issue-number pr-body pr-title) + (first) + (issues/get-issue repo-id))] + (if-not (:commit_sha issue) ; no PR has been merged yet referencing this issue + (do + (log/info "Referenced bounty issue found" owner repo (:issue_number issue)) + (handle-claim issue + user-id + login name + avatar_url + owner repo + repo-id + pr-id + pr-number + head-sha + merged? + event-type)) + (log/info "PR for issue already merged")) (when (= :edited event-type) + ; Remove PR if it does not reference any issue (pull-requests/remove pr-id)))) From 3cdfa549b733eefa265187aa2194f3435850dddd Mon Sep 17 00:00:00 2001 From: Martin Klepsch Date: Tue, 20 Feb 2018 17:52:40 +0100 Subject: [PATCH 2/4] fix #301: add basic stats to manage payouts screen --- resources/templates/home.html | 1 + src/cljs/commiteth/manage_payouts.cljs | 22 ++++++++++++++++++---- 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/resources/templates/home.html b/resources/templates/home.html index 590156e..6afe0ca 100644 --- a/resources/templates/home.html +++ b/resources/templates/home.html @@ -65,6 +65,7 @@ height="0" width="0" style="display:none;visibility:hidden"> src="https://www.facebook.com/tr?id=293089407869419&ev=PageView&noscript=1" /> +