# HG changeset patch # User Marcin Kuzminski # Date 2018-02-15 21:06:50 # Node ID 4e61488e172ce249bc65ab97305c7b6d4f35fcba # Parent 74b83714a52be06369f071e954a431cbdf041e26 integrations: expose some common methods for web based calls of integrations. diff --git a/rhodecode/integrations/types/base.py b/rhodecode/integrations/types/base.py --- a/rhodecode/integrations/types/base.py +++ b/rhodecode/integrations/types/base.py @@ -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:', + + # 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) diff --git a/rhodecode/integrations/types/webhook.py b/rhodecode/integrations/types/webhook.py --- a/rhodecode/integrations/types/webhook.py +++ b/rhodecode/integrations/types/webhook.py @@ -33,7 +33,8 @@ from requests.packages.urllib3.util.retr 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):