diff --git a/build_contracts.sh b/build_contracts.sh index 1c5b503..7b00d8c 100755 --- a/build_contracts.sh +++ b/build_contracts.sh @@ -3,8 +3,10 @@ SOLC=$(which solc) WEB3J=$(which web3j) +rm -f resources/contracts/*.{abi,bin} + # compile contracts -for f in contracts/*.sol; do +for f in contracts/{TokenReg,MultiSigTokenWallet*}.sol; do $SOLC $f --overwrite --bin --abi --optimize -o resources/contracts done diff --git a/resources/templates/index.html b/resources/templates/index.html index 95de5d5..6dfa10c 100644 --- a/resources/templates/index.html +++ b/resources/templates/index.html @@ -77,7 +77,7 @@
diff --git a/src/clj/commiteth/github/core.clj b/src/clj/commiteth/github/core.clj index c20d7ce..e4eadaf 100644 --- a/src/clj/commiteth/github/core.clj +++ b/src/clj/commiteth/github/core.clj @@ -44,7 +44,7 @@ (defn admin-authorize-url [] (if (github-app-enabled?) - (authorize-url "public_repo user:email") + (authorize-url "user:email") (authorize-url "admin:repo_hook repo user:email admin:org_hook"))) (defn access-settings-url [] diff --git a/src/clj/commiteth/routes/services.clj b/src/clj/commiteth/routes/services.clj index 9b72051..82c5633 100644 --- a/src/clj/commiteth/routes/services.clj +++ b/src/clj/commiteth/routes/services.clj @@ -68,9 +68,9 @@ :state 0 :hook_id nil})) +;; NOTE(oskarth): This and above two functions about to be deprecated with Github App (defn handle-toggle-repo [user params can-create?] - (log/debug "handle-toggle-repo" user params) - (log/info "MANUAL ACTION REQUIRED: Possibly add repo:" (pr-str user) (pr-str params)) + (log/info "XXX handle-toggle-repo" (pr-str user) (pr-str params)) (let [{user-id :id} user {repo-id :id full-repo :full_name diff --git a/src/clj/commiteth/routes/webhooks.clj b/src/clj/commiteth/routes/webhooks.clj index 4f30e52..482c4bd 100644 --- a/src/clj/commiteth/routes/webhooks.clj +++ b/src/clj/commiteth/routes/webhooks.clj @@ -1,20 +1,26 @@ (ns commiteth.routes.webhooks - (:require [cheshire.core :as json] - [clojure.string :as str :refer [join]] - [clojure.tools.logging :as log] - [commiteth.bounties :as bounties] - [commiteth.db - [issues :as issues] - [pull-requests :as pull-requests] - [repositories :as repos] - [users :as users]] - [commiteth.github.core :as github] - [commiteth.util.digest :refer [hex-hmac-sha1]] - [compojure.core :refer [defroutes POST]] - [crypto.equality :as crypto] - [ring.util.http-response :refer [ok forbidden]] - [commiteth.db.bounties :as bounties-db] - [clojure.string :as string]) + (:require + [ring.util.http-response :refer [internal-server-error]] + [cheshire.core :as json] + [clojure.string :as str :refer [join]] + [clojure.tools.logging :as log] + [commiteth.bounties :as bounties] + [commiteth.db + [issues :as issues] + [pull-requests :as pull-requests] + [repositories :as repositories] + [users :as users]] + [commiteth.github.core :as github] + [commiteth.util.digest :refer [hex-hmac-sha1]] + ;; TODO(oskarth): Bad form, put these in better namespace + [commiteth.routes.services :refer + [user-whitelisted? + add-bounties-for-existing-issues?]] + [compojure.core :refer [defroutes POST]] + [crypto.equality :as crypto] + [ring.util.http-response :refer [ok forbidden]] + [commiteth.db.bounties :as bounties-db] + [clojure.string :as string]) (:import java.lang.Integer)) (defn find-issue-event @@ -218,6 +224,115 @@ (handle-issue-reopened webhook-payload))) (ok)) +(defn enable-repo-2 [repo-id full-repo] + (log/debug "enable-repo-2" repo-id full-repo) + ;; TODO(oskarth): Add granular permissions to enable creation of label + #_(github/create-label full-repo) + (repositories/update-repo repo-id {:state 2}) + (when (add-bounties-for-existing-issues?) + (bounties/add-bounties-for-existing-issues full-repo))) + +(defn disable-repo-2 [repo-id full-repo] + (log/debug "disable-repo-2" repo-id full-repo) + (repositories/update-repo repo-id {:state 0})) + +(defn full-repo->owner [full-repo] + (try + (let [[owner _] (str/split full-repo #"/")] + owner) + (catch Exception e + (log/error "exception when parsing repo" e) + nil))) + +;; NOTE(oskarth): Together with {enable,disable}-repo-2 above, this replaces +;; handle-toggle-repo for Github App. +(defn handle-add-repo [user-id username owner-avatar-url repo can-create?] + (let [repo-id (:id repo) + repo-name (:name repo) + full-repo (:full_name repo) + _ (log/info "handle-installation add pre repo" (pr-str repo) " " (pr-str full-repo)) + owner (full-repo->owner full-repo) + _ (log/info "handle-installation add" full-repo " " owner) + db-user (users/get-user user-id)] + (log/info "handle-add-repo" + (pr-str {:user-id user-id + :name username + :owner-avatar-url owner-avatar-url + :repo-id repo-id + :repo repo-name + :full-repo full-repo + :can-create? can-create?})) + (cond (not can-create?) + (do (log/info "handle-add-repo user not in whitelist: " username) + {:status 400 + :body "Please join our Riot - chat.status.im/#/register and request + access in our #openbounty room to have your account whitelisted"}) + + (empty? (:address db-user)) + (do (log/info "handle-add-repo user lacking ethereum address: " (pr-str db-user)) + {:status 400 + :body "Please add your ethereum address to your profile first"}) + + :else + (try + (let [_ (log/info "handle-add-repo pre-create") + db-item (repositories/create + {:id repo-id ;; XXX: Being rename twice... silly. + :name repo-name ;; XXX: Is this name of repo? + :owner-avatar-url owner-avatar-url + :user_id user-id + :owner owner}) + _ (log/info "handle-add-repo db-item" db-item) + is-enabled (= 2 (:state db-item))] + (if is-enabled + (disable-repo-2 repo-id full-repo) + (enable-repo-2 repo-id full-repo)) + (ok {:enabled (not is-enabled) + :id repo-id + :full_name full-repo})) + (catch Exception e + (log/error "exception when enabling repo" e) + (repositories/update-repo repo-id {:state -1}) + (internal-server-error)))))) + +(defn handle-installation [{:keys [action repositories sender]}] + ;; TODO(oskarth): Handle other installs, like disable. + (when (= action "created") + (let [user-id (:id sender) + username (:login sender) + owner-avatar-url (:avatar_url sender) + first-repo (first repositories) + can-create? (user-whitelisted? username)] + (log/info "handle-installation created" + (pr-str {:user-id user-id + :name username + :owner-avatar-url owner-avatar-url + :repos repositories})) + (doseq [repo repositories] + (log/info "handle-installation add pre repo" repo) + (handle-add-repo user-id username owner-avatar-url repo can-create?)))) + (ok)) + +(defn handle-installation-repositories [{:keys [action sender] :as payload}] + ;; TODO(oskarth): Handle other installs, like disable. + ;; TODO(oskarth): Also support remove in :repositories_removed + ;; TODO(oskarth): Also support case when :repository_selection is all - does it work differently? + (when (= action "added") + (let [repositories (:repositories_added payload) + user-id (:id sender) + username (:login sender) + owner-avatar-url (:avatar_url sender) + first-repo (first repositories) + can-create? (user-whitelisted? username)] + (log/info "handle-installation-integration created" + (pr-str {:user-id user-id + :name username + :owner-avatar-url owner-avatar-url + :repos repositories})) + (doseq [repo repositories] + (log/info "handle-installation-integration add pre repo" repo) + (handle-add-repo user-id username owner-avatar-url repo can-create?)))) + (ok)) (defn handle-pull-request [pull-request] @@ -232,7 +347,7 @@ (defn validate-secret [webhook-payload raw-payload github-signature] ;; used for oauth app webhooks. secret is repo-specific (let [full-name (get-in webhook-payload [:repository :full_name]) - repo (repos/get-repo full-name) + repo (repositories/get-repo full-name) secret (:hook_secret repo)] (and (not (string/blank? secret)) (crypto/eq? github-signature @@ -268,13 +383,24 @@ (log/debug "webhook-app POST, headers" headers) (let [raw-payload (slurp body) payload (json/parse-string raw-payload true)] - (log/debug "webhook-app POST, payload" payload) + (log/info "webhook-app POST, payload:" (pr-str payload)) (if (validate-secret-one-hook payload raw-payload (get headers "x-hub-signature")) (do (log/debug "Github secret validation OK app") - (log/debug "x-github-event app" (get headers "x-github-event")) + (log/info "x-github-event app" (get headers "x-github-event")) (case (get headers "x-github-event") "issues" (handle-issue payload) "pull_request" (handle-pull-request payload) + "installation" (handle-installation payload) + "installation_repositories" (handle-installation-repositories payload) + + ;; NOTE(oskarth): These two webhooks are / will be deprecated on + ;; November 22, 2017 but they keep being called. According to + ;; documentation they should contain same format. + ;; https://developer.github.com/webhooks/ + "integration_installation" (handle-installation payload) + "integration_installation_repositories" (handle-installation-repositories payload) (ok))) (forbidden))))) + + diff --git a/src/cljs/commiteth/core.cljs b/src/cljs/commiteth/core.cljs index f8550dc..8a90933 100644 --- a/src/cljs/commiteth/core.cljs +++ b/src/cljs/commiteth/core.cljs @@ -79,7 +79,9 @@ (let [tabs (apply conj [[:bounties (str (when-not @user "Open ") "Bounties")] [:activity "Activity"]] (when @user - [[:repos "Repositories"] + [ + ;; NOTE(oskarth) Disabling this as repo management happens through GH app + #_[:repos "Repositories"] [:manage-payouts (str (when-not mobile? "Manage ") "Payouts")] (when (:status-team-member? @user) [:usage-metrics "Usage metrics"])]))] @@ -223,6 +225,10 @@ (secretary/defroute "/" [] (rf/dispatch [:set-active-page :bounties])) +(secretary/defroute "/activity" [] + (rf/dispatch [:set-active-page :activity])) + + (secretary/defroute "/repos" [] (if js/user (rf/dispatch [:set-active-page :repos]) diff --git a/static_langing_page/index.html b/static_langing_page/index.html index 95de5d5..6dfa10c 100644 --- a/static_langing_page/index.html +++ b/static_langing_page/index.html @@ -77,7 +77,7 @@
diff --git a/test/cljs/commiteth/cards.cljs b/test/cljs/commiteth/cards.cljs index a22ebe8..fa240c5 100644 --- a/test/cljs/commiteth/cards.cljs +++ b/test/cljs/commiteth/cards.cljs @@ -106,7 +106,8 @@ (let [active-tab (:active-tab app-state)] [:div.ui.attached.tabular.menu.tiny (for [[tab caption] [[:activity "Activity"] - [:manage "Repositories"] + ;; NOTE(oskarth) Disabling this as repo management happens through GH app + #_[:manage "Repositories"] [:bounties "Bounties"]]] (let [props {:class (str "ui item" (when (= active-tab tab) " active"))