From 98e0531352347ce89eb60e79856b12c8ad2a8334 Mon Sep 17 00:00:00 2001 From: Churikova Tetiana Date: Fri, 2 Mar 2018 21:56:03 +0200 Subject: [PATCH 1/6] New JenkinsFile; Relative path to config; --- test/Jenkinsfile | 3 ++- test/end-to-end/tests/__init__.py | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/test/Jenkinsfile b/test/Jenkinsfile index 8169c6f..16ee5e4 100644 --- a/test/Jenkinsfile +++ b/test/Jenkinsfile @@ -1,7 +1,8 @@ node ('linux1') {sauce('1be1b688-e0e7-4314-92a0-db11f52d3c00') { checkout([$class: 'GitSCM', branches: [[name: '*/develop']], doGenerateSubmoduleConfigurations: false, extensions: [[$class: 'CleanBeforeCheckout']], submoduleCfg: [], userRemoteConfigs: [[url: 'https://github.com/status-im/open-bounty.git']]]) configFileProvider([configFile(fileId: 'sob_automation_test_config', targetLocation: 'test/end-to-end/tests')]) { - try {sh 'cd test/end-to-end/tests && python3 -m pytest -m sanity --build=$BUILD_NAME -v -n 1' + try {withCredentials([string(credentialsId: 'SOB_SAUCE_ACCESS_KEY', variable: 'SAUCE_ACCESS_KEY'), string(credentialsId: 'SOB_SAUCE_USERNAME', variable: 'SAUCE_USERNAME')]) + {sh 'cd test && docker build -t end2end . && docker run --rm -e "SAUCE_USERNAME="${SAUCE_USERNAME} -e "SAUCE_ACCESS_KEY="${SAUCE_ACCESS_KEY} --name end2end-container end2end -m pytest -m sanity --build=$BUILD_NAME -v -n 1'} } finally { saucePublisher() diff --git a/test/end-to-end/tests/__init__.py b/test/end-to-end/tests/__init__.py index 42559c5..5277395 100644 --- a/test/end-to-end/tests/__init__.py +++ b/test/end-to-end/tests/__init__.py @@ -1,4 +1,5 @@ import configparser +import os class TestData(object): @@ -9,7 +10,7 @@ class TestData(object): # define here path to your config.ini file # example - config_example.ini - self.config.read("tests/config.ini") + self.config.read(os.path.join(os.path.abspath(os.path.dirname(__file__)), 'config.ini')) # self.issue['title'] is set in GithubPage::create_new_bounty # self.issue['id'] is set in GithubPage::create_new_bounty From ad794369a1ae54c132d6dda276c3837749993f75 Mon Sep 17 00:00:00 2001 From: Churikova Tetiana Date: Tue, 13 Mar 2018 10:21:30 +0200 Subject: [PATCH 2/6] edit capabilities for sauce labs --- test/end-to-end/tests/basetestcase.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/test/end-to-end/tests/basetestcase.py b/test/end-to-end/tests/basetestcase.py index aa113c4..92e30cc 100644 --- a/test/end-to-end/tests/basetestcase.py +++ b/test/end-to-end/tests/basetestcase.py @@ -18,6 +18,8 @@ class BaseTestCase: sauce_lab_cap = dict() sauce_lab_cap['name'] = test_data.test_name sauce_lab_cap['build'] = pytest.config.getoption('build') + sauce_lab_cap['idleTimeout'] = 900 + sauce_lab_cap['commandTimeout'] = 500 sauce_lab_cap['platform'] = "MAC" sauce_lab_cap['browserName'] = 'Chrome' sauce_lab_cap['screenResolution'] = '2048x1536' @@ -67,8 +69,9 @@ class BaseTestCase: if cls.environment == 'sauce': for caps in cls.capabilities_dev, cls.capabilities_org: - cls.get_remote_caps(cls) + remote = cls.get_remote_caps(cls) new_caps = caps.to_capabilities() + new_caps.update(remote) driver = webdriver.Remote(cls.executor_sauce_lab, desired_capabilities=new_caps) drivers.append(driver) @@ -79,6 +82,7 @@ class BaseTestCase: cls.driver_dev = drivers[0] cls.driver_org = drivers[1] + for driver in drivers: driver.implicitly_wait(10) @@ -132,9 +136,9 @@ class BaseTestCase: remove_installation(cls.driver_org) ######DEV - - cls.github_dev.delete_fork() cls.github_dev.clean_repo_local_folder() + cls.github_dev.delete_fork() + try: cls.driver_dev.quit() cls.driver_org.quit() From b320d4c0ccba8b48ce2268197b47e9c6093e7fd4 Mon Sep 17 00:00:00 2001 From: Churikova Tetiana Date: Tue, 13 Mar 2018 10:36:32 +0200 Subject: [PATCH 3/6] test commit to check GPG signature --- test/end-to-end/tests/basetestcase.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/end-to-end/tests/basetestcase.py b/test/end-to-end/tests/basetestcase.py index 92e30cc..7e75d72 100644 --- a/test/end-to-end/tests/basetestcase.py +++ b/test/end-to-end/tests/basetestcase.py @@ -57,7 +57,7 @@ class BaseTestCase: # # SauceLab capabilities - # + #testcommit to check GPG signature cls.executor_sauce_lab = 'http://%s:%s@ondemand.saucelabs.com:80/wd/hub' % ( environ.get('SAUCE_USERNAME'), environ.get('SAUCE_ACCESS_KEY')) drivers = [] From aa7dd6a1e70b2a931825312f3e05199c2aea4018 Mon Sep 17 00:00:00 2001 From: Churikova Tetiana Date: Tue, 13 Mar 2018 10:38:36 +0200 Subject: [PATCH 4/6] test commit to check GPG signature2 --- test/end-to-end/tests/basetestcase.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/end-to-end/tests/basetestcase.py b/test/end-to-end/tests/basetestcase.py index 7e75d72..aeccf23 100644 --- a/test/end-to-end/tests/basetestcase.py +++ b/test/end-to-end/tests/basetestcase.py @@ -57,7 +57,7 @@ class BaseTestCase: # # SauceLab capabilities - #testcommit to check GPG signature + #testcommit to check GPG signature 2 cls.executor_sauce_lab = 'http://%s:%s@ondemand.saucelabs.com:80/wd/hub' % ( environ.get('SAUCE_USERNAME'), environ.get('SAUCE_ACCESS_KEY')) drivers = [] From 46f5f9f501b4f7f107ae7d9055624bf81b80f17c Mon Sep 17 00:00:00 2001 From: Churikova Tetiana Date: Tue, 13 Mar 2018 10:41:36 +0200 Subject: [PATCH 5/6] test commit to check GPG signature3 --- test/end-to-end/tests/basetestcase.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/end-to-end/tests/basetestcase.py b/test/end-to-end/tests/basetestcase.py index aeccf23..92e30cc 100644 --- a/test/end-to-end/tests/basetestcase.py +++ b/test/end-to-end/tests/basetestcase.py @@ -57,7 +57,7 @@ class BaseTestCase: # # SauceLab capabilities - #testcommit to check GPG signature 2 + # cls.executor_sauce_lab = 'http://%s:%s@ondemand.saucelabs.com:80/wd/hub' % ( environ.get('SAUCE_USERNAME'), environ.get('SAUCE_ACCESS_KEY')) drivers = [] From 13fb8dc4ece31e2eee5601489163d04cecd32626 Mon Sep 17 00:00:00 2001 From: Vitaliy Vlasov Date: Tue, 27 Feb 2018 17:38:27 +0200 Subject: [PATCH 6/6] Update repo name when processing issue/PR webhooks --- resources/sql/queries.sql | 19 ++++---- src/clj/commiteth/db/repositories.clj | 14 ++++-- src/clj/commiteth/routes/services.clj | 68 +-------------------------- src/clj/commiteth/routes/webhooks.clj | 42 ++++++++--------- 4 files changed, 37 insertions(+), 106 deletions(-) diff --git a/resources/sql/queries.sql b/resources/sql/queries.sql index 0673ca6..7737a51 100644 --- a/resources/sql/queries.sql +++ b/resources/sql/queries.sql @@ -102,19 +102,16 @@ WHERE i.repo_id = :repo_id AND i.confirm_hash is null AND i.is_open = true; --- :name update-repo-generic :! :n -/* :require [clojure.string :as string] - [hugsql.parameters :refer [identifier-param-quote]] */ +-- :name update-repo-name :! :n UPDATE repositories -SET -/*~ -(string/join "," - (for [[field _] (:updates params)] - (str (identifier-param-quote (name field) options) - " = :v:updates." (name field)))) -~*/ -where repo_id = :repo_id; +SET repo = :repo_name +WHERE repo_id = :repo_id +AND repo != :repo_name +-- :name update-repo-state :! :n +UPDATE repositories +SET state = :repo_state +WHERE repo_id = :repo_id -- Issues -------------------------------------------------------------------------- diff --git a/src/clj/commiteth/db/repositories.clj b/src/clj/commiteth/db/repositories.clj index 7f23f9a..eb06b38 100644 --- a/src/clj/commiteth/db/repositories.clj +++ b/src/clj/commiteth/db/repositories.clj @@ -25,13 +25,17 @@ (jdbc/with-db-connection [con-db *db*] (db/get-enabled-repositories con-db {:user_id user-id})))) -(defn update-repo - [repo-id updates] +(defn update-repo-name + [repo-id repo-name] (jdbc/with-db-connection [con-db *db*] - (db/update-repo-generic con-db {:repo_id repo-id - :updates updates}))) - + (db/update-repo-name con-db {:repo_id repo-id + :repo_name repo-name}))) +(defn update-repo-state + [repo-id repo-state] + (jdbc/with-db-connection [con-db *db*] + (db/update-repo-name con-db {:repo_id repo-id + :repo_state repo-state}))) (defn get-repo "Get a repo from DB given it's full name (owner/repo-name)" [full-name] diff --git a/src/clj/commiteth/routes/services.clj b/src/clj/commiteth/routes/services.clj index 435b172..5057eb5 100644 --- a/src/clj/commiteth/routes/services.clj +++ b/src/clj/commiteth/routes/services.clj @@ -46,67 +46,6 @@ (log/debug "token" token "member?" member?) member?)) -(defn enable-repo [repo-id repo full-repo token] - (log/debug "enable-repo" repo-id repo) - (when (github/webhook-exists? full-repo token) - (github/remove-our-webhooks full-repo token)) - - (let [hook-secret (random/base64 32)] - (repositories/update-repo repo-id {:state 1 - :hook_secret hook-secret}) - (let [created-hook (github/add-webhook full-repo token hook-secret)] - (log/debug "Created webhook:" created-hook) - (repositories/update-repo repo-id {:hook_id (:id created-hook)}))) - (github/create-label full-repo token) - (repositories/update-repo repo-id {:state 2}) - (when (add-bounties-for-existing-issues?) - (bounties/add-bounties-for-existing-issues full-repo))) - -(defn disable-repo [repo-id full-repo hook-id token] - (log/debug "disable-repo" repo-id full-repo) - (github/remove-webhook full-repo hook-id token) - (repositories/update-repo repo-id {:hook_secret "" - :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/info "XXX handle-toggle-repo" (pr-str user) (pr-str params)) - (let [{user-id :id} user - {repo-id :id - full-repo :full_name - owner-avatar-url :owner-avatar-url - token :token - repo :name} params - [owner _] (str/split full-repo #"/") - db-user (users/get-user (:id user))] - - (cond (not can-create?) - {: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)) - {:status 400 - :body "Please add your ethereum address to your profile first"} - - :else - (try - (let [_ (println "CREATING") - db-item (repositories/create (merge params {:user_id user-id - :owner owner})) - is-enabled (= 2 (:state db-item))] - (if is-enabled - (disable-repo repo-id full-repo (:hook_id db-item) token) - (enable-repo repo-id repo full-repo token)) - (ok (merge - {:enabled (not is-enabled)} - (select-keys params [:id :full_name])))) - (catch Exception e - (log/error "exception when enabling repo" e) - (repositories/update-repo repo-id {:state -1}) - (internal-server-error)))))) - (defn in? [coll elem] (some #(= elem %) coll)) @@ -286,9 +225,4 @@ :auth-rules authenticated? :current-user user (log/debug "/user/bounties") - (ok (user-bounties user))) - (POST "/repository/toggle" {:keys [params]} - ;; NOTE: Don't allow anyone to create repos; manual add - :auth-rules authenticated? - :current-user user - (handle-toggle-repo user params (user-whitelisted? (:login user))))))) + (ok (user-bounties user)))))) diff --git a/src/clj/commiteth/routes/webhooks.clj b/src/clj/commiteth/routes/webhooks.clj index 8ab27bc..e12ccd6 100644 --- a/src/clj/commiteth/routes/webhooks.clj +++ b/src/clj/commiteth/routes/webhooks.clj @@ -199,9 +199,15 @@ new-title (:title gh-issue)] (issues/update-issue-title issue-id new-title))) +(defn update-repo-name [webhook-payload] + "Update repo name in DB if changed" + (let [{repo-id :id + repo-name :name} (:repository webhook-payload)] + (repositories/update-repo-name repo-id repo-name))) (defn handle-issue [webhook-payload] + (update-repo-name webhook-payload) (when-let [action (:action webhook-payload)] (log/debug "handle-issue" action) (when (labeled-as-bounty? action webhook-payload) @@ -216,17 +222,17 @@ (handle-issue-reopened webhook-payload))) (ok)) -(defn enable-repo-2 [repo-id full-repo] - (log/debug "enable-repo-2" repo-id full-repo) +(defn enable-repo [repo-id full-repo] + (log/debug "enable-repo" 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}) + (repositories/update-repo-state repo-id 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 disable-repo [repo-id full-repo] + (log/debug "disable-repo" repo-id full-repo) + (repositories/update-repo-state repo-id 0)) (defn full-repo->owner [full-repo] (try @@ -236,8 +242,6 @@ (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) @@ -277,14 +281,14 @@ _ (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)) + (disable-repo repo-id full-repo) + (enable-repo 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}) + (repositories/update-repo-state repo-id -1) (internal-server-error)))))) (defn handle-installation [{:keys [action installation repositories sender]}] @@ -327,12 +331,13 @@ (ok)) (defn handle-pull-request - [pull-request] - (let [action (keyword (:action pull-request))] + [webhook-payload] + (update-repo-name webhook-payload) + (let [action (keyword (:action webhook-payload))] (when (contains? #{:opened :edited :closed} action) - (handle-pull-request-event action pull-request)) + (handle-pull-request-event action webhook-payload)) (ok))) @@ -385,14 +390,5 @@ "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))))) - -