Add support for using org repos
Now repositories are shown with their full name ('<org/user>/repo' instead of 'repo') and it is possible to add bounties for both user repositories and organization repositories. Using org repos requires the user to have admin rights to the repo.
This commit is contained in:
parent
e68891a936
commit
60cc76919e
|
@ -9,7 +9,8 @@
|
||||||
[commiteth.config :refer [env]]
|
[commiteth.config :refer [env]]
|
||||||
[digest :refer [sha-256]]
|
[digest :refer [sha-256]]
|
||||||
[clojure.tools.logging :as log]
|
[clojure.tools.logging :as log]
|
||||||
[cheshire.core :as json])
|
[cheshire.core :as json]
|
||||||
|
[clojure.string :as str])
|
||||||
(:import [java.util UUID]))
|
(:import [java.util UUID]))
|
||||||
|
|
||||||
(def ^:dynamic url "https://api.github.com/")
|
(def ^:dynamic url "https://api.github.com/")
|
||||||
|
@ -25,7 +26,7 @@
|
||||||
(defn authorize-url []
|
(defn authorize-url []
|
||||||
(let [params (codec/form-encode {:client_id (client-id)
|
(let [params (codec/form-encode {:client_id (client-id)
|
||||||
:redirect_uri (redirect-uri)
|
:redirect_uri (redirect-uri)
|
||||||
:scope "admin:repo_hook repo"
|
:scope "admin:repo_hook repo admin:org_hook"
|
||||||
:allow_signup true
|
:allow_signup true
|
||||||
:state (str (UUID/randomUUID))})]
|
:state (str (UUID/randomUUID))})]
|
||||||
(str "https://github.com/login/oauth/authorize" "?" params)))
|
(str "https://github.com/login/oauth/authorize" "?" params)))
|
||||||
|
@ -82,19 +83,21 @@
|
||||||
(users/me (auth-params token)))
|
(users/me (auth-params token)))
|
||||||
|
|
||||||
(defn add-webhook
|
(defn add-webhook
|
||||||
[user repo token]
|
[full-repo token]
|
||||||
(log/debug "adding webhook" (str user "/" repo) token)
|
(log/debug "adding webhook" full-repo token)
|
||||||
|
(let [[user repo] (str/split full-repo #"/")]
|
||||||
(repos/create-hook user repo "web"
|
(repos/create-hook user repo "web"
|
||||||
{:url (str (server-address) "/webhook")
|
{:url (str (server-address) "/webhook")
|
||||||
:content_type "json"}
|
:content_type "json"}
|
||||||
(merge (auth-params token)
|
(merge (auth-params token)
|
||||||
{:events ["issues", "issue_comment", "pull_request"]
|
{:events ["issues", "issue_comment", "pull_request"]
|
||||||
:active true})))
|
:active true}))))
|
||||||
|
|
||||||
(defn remove-webhook
|
(defn remove-webhook
|
||||||
[user repo hook-id token]
|
[full-repo hook-id token]
|
||||||
|
(let [[user repo] (str/split full-repo #"/")]
|
||||||
(log/debug "removing webhook" (str user "/" repo) hook-id token)
|
(log/debug "removing webhook" (str user "/" repo) hook-id token)
|
||||||
(repos/delete-hook user repo hook-id (auth-params token)))
|
(repos/delete-hook user repo hook-id (auth-params token))))
|
||||||
|
|
||||||
(defn github-comment-hash
|
(defn github-comment-hash
|
||||||
[user repo issue-number]
|
[user repo issue-number]
|
||||||
|
@ -138,7 +141,12 @@
|
||||||
(when oauth-token
|
(when oauth-token
|
||||||
{:headers {"Authorization" (str "token " oauth-token)}}))
|
{:headers {"Authorization" (str "token " oauth-token)}}))
|
||||||
raw-query (:raw query)
|
raw-query (:raw query)
|
||||||
proper-query (tentacles/query-map (dissoc query :auth :oauth-token :all-pages :accept :user-agent :otp))]
|
proper-query (tentacles/query-map (dissoc query :auth
|
||||||
|
:oauth-token
|
||||||
|
:all-pages
|
||||||
|
:accept
|
||||||
|
:user-agent
|
||||||
|
:otp))]
|
||||||
(assoc req :body (json/generate-string (or raw-query proper-query)))))
|
(assoc req :body (json/generate-string (or raw-query proper-query)))))
|
||||||
|
|
||||||
(defn update-comment
|
(defn update-comment
|
||||||
|
@ -146,7 +154,8 @@
|
||||||
(let [comment (generate-comment user repo issue-number balance)]
|
(let [comment (generate-comment user repo issue-number balance)]
|
||||||
(log/debug (str "Updating " user "/" repo "/" issue-number " comment #" comment-id " with contents: " comment))
|
(log/debug (str "Updating " user "/" repo "/" issue-number " comment #" comment-id " with contents: " comment))
|
||||||
(let [req (make-patch-request "repos/%s/%s/issues/comments/%s"
|
(let [req (make-patch-request "repos/%s/%s/issues/comments/%s"
|
||||||
[user repo comment-id] (assoc (self-auth-params) :body comment))]
|
[user repo comment-id]
|
||||||
|
(assoc (self-auth-params) :body comment))]
|
||||||
(tentacles/safe-parse (http/request req)))))
|
(tentacles/safe-parse (http/request req)))))
|
||||||
|
|
||||||
(defn get-issue
|
(defn get-issue
|
||||||
|
@ -158,6 +167,7 @@
|
||||||
(issues/issue-events user repo issue-id (self-auth-params)))
|
(issues/issue-events user repo issue-id (self-auth-params)))
|
||||||
|
|
||||||
(defn create-label
|
(defn create-label
|
||||||
[user repo token]
|
[full-repo token]
|
||||||
|
(let [[user repo] (str/split full-repo #"/")]
|
||||||
(log/debug "creating bounty label" (str user "/" repo) token)
|
(log/debug "creating bounty label" (str user "/" repo) token)
|
||||||
(issues/create-label user repo "bounty" "00ff00" (auth-params token)))
|
(issues/create-label user repo "bounty" "00ff00" (auth-params token))))
|
||||||
|
|
|
@ -77,7 +77,7 @@
|
||||||
:auth-rules authenticated?
|
:auth-rules authenticated?
|
||||||
:current-user user
|
:current-user user
|
||||||
(ok (let [{repo-id :id
|
(ok (let [{repo-id :id
|
||||||
repo :name} params
|
repo :full_name} params
|
||||||
{token :token
|
{token :token
|
||||||
login :login
|
login :login
|
||||||
user-id :id} user
|
user-id :id} user
|
||||||
|
@ -86,9 +86,9 @@
|
||||||
(repositories/toggle repo-id))]
|
(repositories/toggle repo-id))]
|
||||||
(if (:enabled result)
|
(if (:enabled result)
|
||||||
;; @todo: do we really want to make this call at this moment?
|
;; @todo: do we really want to make this call at this moment?
|
||||||
(let [created-hook (github/add-webhook login repo token)]
|
(let [created-hook (github/add-webhook repo token)]
|
||||||
(log/debug "Created webhook:" created-hook)
|
(log/debug "Created webhook:" created-hook)
|
||||||
(github/create-label login repo token)
|
(github/create-label repo token)
|
||||||
(repositories/update-hook-id repo-id (:id created-hook)))
|
(repositories/update-hook-id repo-id (:id created-hook)))
|
||||||
(github/remove-webhook login repo (:hook_id result) token))
|
(github/remove-webhook repo (:hook_id result) token))
|
||||||
result)))))
|
result)))))
|
||||||
|
|
|
@ -137,11 +137,12 @@
|
||||||
(reg-event-fx
|
(reg-event-fx
|
||||||
:toggle-repo
|
:toggle-repo
|
||||||
(fn [{:keys [db]} [_ repo]]
|
(fn [{:keys [db]} [_ repo]]
|
||||||
|
(println "toggle-repo" repo)
|
||||||
{:db db
|
{:db db
|
||||||
:http {:method POST
|
:http {:method POST
|
||||||
:url "/api/repository/toggle"
|
:url "/api/repository/toggle"
|
||||||
:on-success #(println %)
|
:on-success #(println %)
|
||||||
:params (select-keys repo [:id :login :name])}}))
|
:params (select-keys repo [:id :login :full_name :name])}}))
|
||||||
|
|
||||||
(reg-event-fx
|
(reg-event-fx
|
||||||
:save-user-address
|
:save-user-address
|
||||||
|
|
|
@ -8,7 +8,7 @@
|
||||||
(defn repository-row [repo]
|
(defn repository-row [repo]
|
||||||
(let [{repo-id :id
|
(let [{repo-id :id
|
||||||
url :html_url
|
url :html_url
|
||||||
name :name
|
name :full_name
|
||||||
description :description} repo]
|
description :description} repo]
|
||||||
^{:key repo-id}
|
^{:key repo-id}
|
||||||
[:div.d-table.width-full
|
[:div.d-table.width-full
|
||||||
|
|
Loading…
Reference in New Issue