# HG changeset patch # User Marcin Kuzminski # Date 2017-04-28 18:05:15 # Node ID 48d816cec44e0d78f65d1ae71e9cad9a6671569d # Parent 45730755b919659d8b2a4c33f81cb4f48b3d1920 integrations: expose actor user_id, and username in webhook integration templates args. ref #5287 diff --git a/rhodecode/events/base.py b/rhodecode/events/base.py --- a/rhodecode/events/base.py +++ b/rhodecode/events/base.py @@ -24,7 +24,8 @@ from rhodecode.lib.utils2 import Attribu # this is a user object to be used for events caused by the system (eg. shell) SYSTEM_USER = AttributeDict(dict( - username='__SYSTEM__' + username='__SYSTEM__', + user_id='__SYSTEM_ID__' )) log = logging.getLogger(__name__) @@ -61,7 +62,8 @@ class RhodecodeEvent(object): instance = auth_user.get_instance() if not instance: return AttributeDict(dict( - username=auth_user.username + username=auth_user.username, + user_id=auth_user.user_id, )) return instance @@ -93,7 +95,8 @@ class RhodecodeEvent(object): 'utc_timestamp': self.utc_timestamp, 'actor_ip': self.actor_ip, 'actor': { - 'username': self.actor.username + 'username': self.actor.username, + 'user_id': self.actor.user_id }, 'server_url': self.server_url } 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 @@ -35,7 +35,7 @@ from rhodecode.integrations.types.base i log = logging.getLogger(__name__) -# updating this required to update the `base_vars` passed in url calling func +# updating this required to update the `common_vars` passed in url calling func WEBHOOK_URL_VARS = [ 'repo_name', 'repo_type', @@ -50,6 +50,10 @@ WEBHOOK_URL_VARS = [ 'pull_request_id', 'pull_request_url', + # user who triggers the call + 'username', + 'user_id', + ] URL_VARS = ', '.join('${' + x + '}' for x in WEBHOOK_URL_VARS) @@ -70,6 +74,8 @@ class WebhookHandler(object): 'repo_type': data['repo']['repo_type'], 'repo_id': data['repo']['repo_id'], 'repo_url': data['repo']['url'], + 'username': data['actor']['username'], + 'user_id': data['actor']['user_id'] } return string.Template( diff --git a/rhodecode/tests/integrations/test_webhook.py b/rhodecode/tests/integrations/test_webhook.py --- a/rhodecode/tests/integrations/test_webhook.py +++ b/rhodecode/tests/integrations/test_webhook.py @@ -32,7 +32,11 @@ def base_data(): 'repo_name': 'foo', 'repo_type': 'hg', 'repo_id': '12', - 'url': 'http://repo.url/foo' + 'url': 'http://repo.url/foo', + }, + 'actor': { + 'username': 'actor_name', + 'user_id': 1 } }