integrations: expose some common methods for web based calls of integrations.

This commit is contained in:
Marcin Kuzminski 2018-02-15 22:06:50 +01:00
parent 7b8ed2a23e
commit 5fbf01cea3
2 changed files with 32 additions and 3 deletions

View file

@ -114,7 +114,31 @@ class EEIntegration(IntegrationTypeBase):
super(EEIntegration, self).__init__(settings)
# Helpers
# Helpers #
# common vars for url template
CI_URL_VARS = [
'repo_name',
'repo_type',
'repo_id',
'repo_url',
# extra repo fields
'extra:<extra_key_name>',
# special attrs below that we handle, using multi-call
'branch',
'commit_id',
# pr events vars
'pull_request_id',
'pull_request_url',
# user who triggers the call
'username',
'user_id',
]
def get_auth(settings):
from requests.auth import HTTPBasicAuth
@ -123,3 +147,7 @@ def get_auth(settings):
if username and password:
return HTTPBasicAuth(username, password)
return None
def get_url_vars(url_vars):
return ', '.join('${' + x + '}' for x in url_vars)

View file

@ -33,7 +33,8 @@ from requests.packages.urllib3.util.retry import Retry
import rhodecode
from rhodecode import events
from rhodecode.translation import _
from rhodecode.integrations.types.base import IntegrationTypeBase, get_auth
from rhodecode.integrations.types.base import (
IntegrationTypeBase, get_auth, get_url_vars)
from rhodecode.lib.celerylib import run_task, async_task, RequestContextTask
log = logging.getLogger(__name__)
@ -61,7 +62,7 @@ WEBHOOK_URL_VARS = [
'user_id',
]
URL_VARS = ', '.join('${' + x + '}' for x in WEBHOOK_URL_VARS)
URL_VARS = get_url_vars(WEBHOOK_URL_VARS)
class WebhookHandler(object):