Merge branch 'develop' into fix/update-github-comment-339

This commit is contained in:
Tetiana Churikova 2018-03-16 12:23:47 +02:00 committed by GitHub
commit 75d307fe47
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 48 additions and 111 deletions

View File

@ -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 --------------------------------------------------------------------------

View File

@ -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]

View File

@ -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))))))

View File

@ -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)))))

3
test/Jenkinsfile vendored
View File

@ -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()

View File

@ -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

View File

@ -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()