mirror of
https://github.com/status-im/open-bounty.git
synced 2025-01-11 18:14:25 +00:00
Merge branch 'develop' into fix/update-github-comment-339
This commit is contained in:
commit
75d307fe47
@ -102,19 +102,16 @@ WHERE i.repo_id = :repo_id
|
|||||||
AND i.confirm_hash is null
|
AND i.confirm_hash is null
|
||||||
AND i.is_open = true;
|
AND i.is_open = true;
|
||||||
|
|
||||||
-- :name update-repo-generic :! :n
|
-- :name update-repo-name :! :n
|
||||||
/* :require [clojure.string :as string]
|
|
||||||
[hugsql.parameters :refer [identifier-param-quote]] */
|
|
||||||
UPDATE repositories
|
UPDATE repositories
|
||||||
SET
|
SET repo = :repo_name
|
||||||
/*~
|
WHERE repo_id = :repo_id
|
||||||
(string/join ","
|
AND repo != :repo_name
|
||||||
(for [[field _] (:updates params)]
|
|
||||||
(str (identifier-param-quote (name field) options)
|
|
||||||
" = :v:updates." (name field))))
|
|
||||||
~*/
|
|
||||||
where repo_id = :repo_id;
|
|
||||||
|
|
||||||
|
-- :name update-repo-state :! :n
|
||||||
|
UPDATE repositories
|
||||||
|
SET state = :repo_state
|
||||||
|
WHERE repo_id = :repo_id
|
||||||
|
|
||||||
|
|
||||||
-- Issues --------------------------------------------------------------------------
|
-- Issues --------------------------------------------------------------------------
|
||||||
|
@ -25,13 +25,17 @@
|
|||||||
(jdbc/with-db-connection [con-db *db*]
|
(jdbc/with-db-connection [con-db *db*]
|
||||||
(db/get-enabled-repositories con-db {:user_id user-id}))))
|
(db/get-enabled-repositories con-db {:user_id user-id}))))
|
||||||
|
|
||||||
(defn update-repo
|
(defn update-repo-name
|
||||||
[repo-id updates]
|
[repo-id repo-name]
|
||||||
(jdbc/with-db-connection [con-db *db*]
|
(jdbc/with-db-connection [con-db *db*]
|
||||||
(db/update-repo-generic con-db {:repo_id repo-id
|
(db/update-repo-name con-db {:repo_id repo-id
|
||||||
:updates updates})))
|
: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
|
(defn get-repo
|
||||||
"Get a repo from DB given it's full name (owner/repo-name)"
|
"Get a repo from DB given it's full name (owner/repo-name)"
|
||||||
[full-name]
|
[full-name]
|
||||||
|
@ -46,67 +46,6 @@
|
|||||||
(log/debug "token" token "member?" member?)
|
(log/debug "token" token "member?" 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]
|
(defn in? [coll elem]
|
||||||
(some #(= elem %) coll))
|
(some #(= elem %) coll))
|
||||||
|
|
||||||
@ -286,9 +225,4 @@
|
|||||||
:auth-rules authenticated?
|
:auth-rules authenticated?
|
||||||
:current-user user
|
:current-user user
|
||||||
(log/debug "/user/bounties")
|
(log/debug "/user/bounties")
|
||||||
(ok (user-bounties user)))
|
(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)))))))
|
|
||||||
|
@ -199,9 +199,15 @@
|
|||||||
new-title (:title gh-issue)]
|
new-title (:title gh-issue)]
|
||||||
(issues/update-issue-title issue-id new-title)))
|
(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
|
(defn handle-issue
|
||||||
[webhook-payload]
|
[webhook-payload]
|
||||||
|
(update-repo-name webhook-payload)
|
||||||
(when-let [action (:action webhook-payload)]
|
(when-let [action (:action webhook-payload)]
|
||||||
(log/debug "handle-issue" action)
|
(log/debug "handle-issue" action)
|
||||||
(when (labeled-as-bounty? action webhook-payload)
|
(when (labeled-as-bounty? action webhook-payload)
|
||||||
@ -216,17 +222,17 @@
|
|||||||
(handle-issue-reopened webhook-payload)))
|
(handle-issue-reopened webhook-payload)))
|
||||||
(ok))
|
(ok))
|
||||||
|
|
||||||
(defn enable-repo-2 [repo-id full-repo]
|
(defn enable-repo [repo-id full-repo]
|
||||||
(log/debug "enable-repo-2" repo-id full-repo)
|
(log/debug "enable-repo" repo-id full-repo)
|
||||||
;; TODO(oskarth): Add granular permissions to enable creation of label
|
;; TODO(oskarth): Add granular permissions to enable creation of label
|
||||||
#_(github/create-label full-repo)
|
#_(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?)
|
(when (add-bounties-for-existing-issues?)
|
||||||
(bounties/add-bounties-for-existing-issues full-repo)))
|
(bounties/add-bounties-for-existing-issues full-repo)))
|
||||||
|
|
||||||
(defn disable-repo-2 [repo-id full-repo]
|
(defn disable-repo [repo-id full-repo]
|
||||||
(log/debug "disable-repo-2" repo-id full-repo)
|
(log/debug "disable-repo" repo-id full-repo)
|
||||||
(repositories/update-repo repo-id {:state 0}))
|
(repositories/update-repo-state repo-id 0))
|
||||||
|
|
||||||
(defn full-repo->owner [full-repo]
|
(defn full-repo->owner [full-repo]
|
||||||
(try
|
(try
|
||||||
@ -236,8 +242,6 @@
|
|||||||
(log/error "exception when parsing repo" e)
|
(log/error "exception when parsing repo" e)
|
||||||
nil)))
|
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?]
|
(defn handle-add-repo [user-id username owner-avatar-url repo can-create?]
|
||||||
(let [repo-id (:id repo)
|
(let [repo-id (:id repo)
|
||||||
repo-name (:name repo)
|
repo-name (:name repo)
|
||||||
@ -277,14 +281,14 @@
|
|||||||
_ (log/info "handle-add-repo db-item" db-item)
|
_ (log/info "handle-add-repo db-item" db-item)
|
||||||
is-enabled (= 2 (:state db-item))]
|
is-enabled (= 2 (:state db-item))]
|
||||||
(if is-enabled
|
(if is-enabled
|
||||||
(disable-repo-2 repo-id full-repo)
|
(disable-repo repo-id full-repo)
|
||||||
(enable-repo-2 repo-id full-repo))
|
(enable-repo repo-id full-repo))
|
||||||
(ok {:enabled (not is-enabled)
|
(ok {:enabled (not is-enabled)
|
||||||
:id repo-id
|
:id repo-id
|
||||||
:full_name full-repo}))
|
:full_name full-repo}))
|
||||||
(catch Exception e
|
(catch Exception e
|
||||||
(log/error "exception when enabling repo" 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))))))
|
(internal-server-error))))))
|
||||||
|
|
||||||
(defn handle-installation [{:keys [action installation repositories sender]}]
|
(defn handle-installation [{:keys [action installation repositories sender]}]
|
||||||
@ -327,12 +331,13 @@
|
|||||||
(ok))
|
(ok))
|
||||||
|
|
||||||
(defn handle-pull-request
|
(defn handle-pull-request
|
||||||
[pull-request]
|
[webhook-payload]
|
||||||
(let [action (keyword (:action pull-request))]
|
(update-repo-name webhook-payload)
|
||||||
|
(let [action (keyword (:action webhook-payload))]
|
||||||
(when (contains? #{:opened
|
(when (contains? #{:opened
|
||||||
:edited
|
:edited
|
||||||
:closed} action)
|
:closed} action)
|
||||||
(handle-pull-request-event action pull-request))
|
(handle-pull-request-event action webhook-payload))
|
||||||
(ok)))
|
(ok)))
|
||||||
|
|
||||||
|
|
||||||
@ -385,14 +390,5 @@
|
|||||||
"pull_request" (handle-pull-request payload)
|
"pull_request" (handle-pull-request payload)
|
||||||
"installation" (handle-installation payload)
|
"installation" (handle-installation payload)
|
||||||
"installation_repositories" (handle-installation-repositories 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)))
|
(ok)))
|
||||||
(forbidden)))))
|
(forbidden)))))
|
||||||
|
|
||||||
|
|
||||||
|
3
test/Jenkinsfile
vendored
3
test/Jenkinsfile
vendored
@ -1,7 +1,8 @@
|
|||||||
node ('linux1') {sauce('1be1b688-e0e7-4314-92a0-db11f52d3c00') {
|
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']]])
|
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')]) {
|
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 {
|
finally {
|
||||||
saucePublisher()
|
saucePublisher()
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
import configparser
|
import configparser
|
||||||
|
import os
|
||||||
|
|
||||||
class TestData(object):
|
class TestData(object):
|
||||||
|
|
||||||
@ -9,7 +10,7 @@ class TestData(object):
|
|||||||
# define here path to your config.ini file
|
# define here path to your config.ini file
|
||||||
# example - config_example.ini
|
# 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['title'] is set in GithubPage::create_new_bounty
|
||||||
# self.issue['id'] is set in GithubPage::create_new_bounty
|
# self.issue['id'] is set in GithubPage::create_new_bounty
|
||||||
|
@ -18,6 +18,8 @@ class BaseTestCase:
|
|||||||
sauce_lab_cap = dict()
|
sauce_lab_cap = dict()
|
||||||
sauce_lab_cap['name'] = test_data.test_name
|
sauce_lab_cap['name'] = test_data.test_name
|
||||||
sauce_lab_cap['build'] = pytest.config.getoption('build')
|
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['platform'] = "MAC"
|
||||||
sauce_lab_cap['browserName'] = 'Chrome'
|
sauce_lab_cap['browserName'] = 'Chrome'
|
||||||
sauce_lab_cap['screenResolution'] = '2048x1536'
|
sauce_lab_cap['screenResolution'] = '2048x1536'
|
||||||
@ -67,8 +69,9 @@ class BaseTestCase:
|
|||||||
|
|
||||||
if cls.environment == 'sauce':
|
if cls.environment == 'sauce':
|
||||||
for caps in cls.capabilities_dev, cls.capabilities_org:
|
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 = caps.to_capabilities()
|
||||||
|
new_caps.update(remote)
|
||||||
driver = webdriver.Remote(cls.executor_sauce_lab,
|
driver = webdriver.Remote(cls.executor_sauce_lab,
|
||||||
desired_capabilities=new_caps)
|
desired_capabilities=new_caps)
|
||||||
drivers.append(driver)
|
drivers.append(driver)
|
||||||
@ -79,6 +82,7 @@ class BaseTestCase:
|
|||||||
cls.driver_dev = drivers[0]
|
cls.driver_dev = drivers[0]
|
||||||
cls.driver_org = drivers[1]
|
cls.driver_org = drivers[1]
|
||||||
|
|
||||||
|
|
||||||
for driver in drivers:
|
for driver in drivers:
|
||||||
driver.implicitly_wait(10)
|
driver.implicitly_wait(10)
|
||||||
|
|
||||||
@ -132,9 +136,9 @@ class BaseTestCase:
|
|||||||
remove_installation(cls.driver_org)
|
remove_installation(cls.driver_org)
|
||||||
|
|
||||||
######DEV
|
######DEV
|
||||||
|
|
||||||
cls.github_dev.delete_fork()
|
|
||||||
cls.github_dev.clean_repo_local_folder()
|
cls.github_dev.clean_repo_local_folder()
|
||||||
|
cls.github_dev.delete_fork()
|
||||||
|
|
||||||
try:
|
try:
|
||||||
cls.driver_dev.quit()
|
cls.driver_dev.quit()
|
||||||
cls.driver_org.quit()
|
cls.driver_org.quit()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user