Validate referenced issue number

This commit is contained in:
kagel 2016-09-01 02:59:43 +03:00
parent e1c7b08174
commit 094ce72a46
2 changed files with 22 additions and 8 deletions

View File

@ -8,7 +8,7 @@
[commiteth.config :refer [env]]) [commiteth.config :refer [env]])
(:import [java.util UUID])) (:import [java.util UUID]))
(defn server-address [] (:server-address env)) (defn server-address [] (:server-address env))
(defn client-id [] (:github-client-id env)) (defn client-id [] (:github-client-id env))
(defn client-secret [] (:github-client-secret env)) (defn client-secret [] (:github-client-secret env))
(defn redirect-uri [] (str (server-address) "/callback")) (defn redirect-uri [] (str (server-address) "/callback"))
@ -101,6 +101,10 @@
[user repo commit-id] [user repo commit-id]
(repos/specific-commit user repo commit-id (self-auth-params))) (repos/specific-commit user repo commit-id (self-auth-params)))
(defn get-issue
[user repo issue-number]
(issues/specific-issue user repo issue-number (self-auth-params)))
(defn get-issue-events (defn get-issue-events
[user repo issue-id] [user repo issue-id]
(issues/issue-events user repo issue-id (self-auth-params))) (issues/issue-events user repo issue-id (self-auth-params)))

View File

@ -53,6 +53,18 @@
(catch NumberFormatException _))) (catch NumberFormatException _)))
(re-seq % pr-body)) keywords)) (re-seq % pr-body)) keywords))
(defn has-bounty-label?
[issue]
(let [labels (:labels issue)]
(some #(= label-name (:name %)) labels)))
(defn validate-issue-number
"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 (has-bounty-label? issue)
issue-number)))
(defn handle-pull-request-closed (defn handle-pull-request-closed
[{{{owner :login} :owner [{{{owner :login} :owner
repo :name repo :name
@ -65,7 +77,10 @@
pr-body :body} :pull_request}] pr-body :body} :pull_request}]
(future (future
(let [commit-id (find-commit-id owner repo pr-number "merged") (let [commit-id (find-commit-id owner repo pr-number "merged")
issue-number (first (extract-issue-number pr-body)) issue-number (->>
(extract-issue-number pr-body)
(first)
(validate-issue-number owner repo))
m {:commit_id commit-id :issue_number issue-number}] m {:commit_id commit-id :issue_number issue-number}]
(when (or commit-id issue-number) (when (or commit-id issue-number)
(pull-requests/create (merge m {:repo_id repo-id (pull-requests/create (merge m {:repo_id repo-id
@ -80,11 +95,6 @@
(= "labeled" action) (= "labeled" action)
(= label-name (get-in issue [:label :name])))) (= label-name (get-in issue [:label :name]))))
(defn has-bounty-label?
[issue]
(let [labels (get-in issue [:issue :labels])]
(some #(= label-name (:name %)) labels)))
(defn gen-address [] (defn gen-address []
(UUID/randomUUID)) (UUID/randomUUID))
@ -105,7 +115,7 @@
(issues/create repo-id issue-id issue-number issue-title issue-address))) (issues/create repo-id issue-id issue-number issue-title issue-address)))
(when (and (when (and
(= "closed" action) (= "closed" action)
(has-bounty-label? issue)) (has-bounty-label? (:issue issue)))
(handle-issue-closed issue))) (handle-issue-closed issue)))
(ok (str issue))) (ok (str issue)))