##// END OF EJS Templates
webhook: enable support of extra repo variables as replacement in template url.
marcink -
r1761:8612110c default
parent child Browse files
Show More
@@ -16,6 +16,7 b''
16 # RhodeCode Enterprise Edition, including its added features, Support services,
16 # RhodeCode Enterprise Edition, including its added features, Support services,
17 # and proprietary license terms, please see https://rhodecode.com/licenses/
17 # and proprietary license terms, please see https://rhodecode.com/licenses/
18
18
19 import collections
19 import logging
20 import logging
20
21
21 from rhodecode.translation import lazy_ugettext
22 from rhodecode.translation import lazy_ugettext
@@ -75,9 +76,10 b' def _commits_as_dict(commit_ids, repos):'
75 urlified_message, issues_data = process_patterns(
76 urlified_message, issues_data = process_patterns(
76 cs_data['message'], repo.repo_name)
77 cs_data['message'], repo.repo_name)
77 cs_data['issues'] = issues_data
78 cs_data['issues'] = issues_data
78 cs_data['message_html'] = urlify_commit_message(cs_data['message'],
79 cs_data['message_html'] = urlify_commit_message(
79 repo.repo_name)
80 cs_data['message'], repo.repo_name)
80 cs_data['message_html_title'] = chop_at_smart(cs_data['message'], '\n', suffix_if_chopped='...')
81 cs_data['message_html_title'] = chop_at_smart(
82 cs_data['message'], '\n', suffix_if_chopped='...')
81 commits.append(cs_data)
83 commits.append(cs_data)
82
84
83 needed_commits.remove(commit_id)
85 needed_commits.remove(commit_id)
@@ -118,12 +120,17 b' class RepoEvent(RhodecodeEvent):'
118 def as_dict(self):
120 def as_dict(self):
119 from rhodecode.model.repo import RepoModel
121 from rhodecode.model.repo import RepoModel
120 data = super(RepoEvent, self).as_dict()
122 data = super(RepoEvent, self).as_dict()
123 extra_fields = collections.OrderedDict()
124 for field in self.repo.extra_fields:
125 extra_fields[field.field_key] = field.field_value
126
121 data.update({
127 data.update({
122 'repo': {
128 'repo': {
123 'repo_id': self.repo.repo_id,
129 'repo_id': self.repo.repo_id,
124 'repo_name': self.repo.repo_name,
130 'repo_name': self.repo.repo_name,
125 'repo_type': self.repo.repo_type,
131 'repo_type': self.repo.repo_type,
126 'url': RepoModel().get_url(self.repo)
132 'url': RepoModel().get_url(self.repo),
133 'extra_fields': extra_fields
127 }
134 }
128 })
135 })
129 return data
136 return data
@@ -41,6 +41,8 b' WEBHOOK_URL_VARS = ['
41 'repo_type',
41 'repo_type',
42 'repo_id',
42 'repo_id',
43 'repo_url',
43 'repo_url',
44 # extra repo fields
45 'extra:<extra_key_name>',
44
46
45 # special attrs below that we handle, using multi-call
47 # special attrs below that we handle, using multi-call
46 'branch',
48 'branch',
@@ -77,6 +79,10 b' class WebhookHandler(object):'
77 'username': data['actor']['username'],
79 'username': data['actor']['username'],
78 'user_id': data['actor']['user_id']
80 'user_id': data['actor']['user_id']
79 }
81 }
82 extra_vars = {}
83 for extra_key, extra_val in data['repo']['extra_fields'].items():
84 extra_vars['extra:{}'.format(extra_key)] = extra_val
85 common_vars.update(extra_vars)
80
86
81 return string.Template(
87 return string.Template(
82 self.template_url).safe_substitute(**common_vars)
88 self.template_url).safe_substitute(**common_vars)
@@ -33,6 +33,7 b' def base_data():'
33 'repo_type': 'hg',
33 'repo_type': 'hg',
34 'repo_id': '12',
34 'repo_id': '12',
35 'url': 'http://repo.url/foo',
35 'url': 'http://repo.url/foo',
36 'extra_fields': {},
36 },
37 },
37 'actor': {
38 'actor': {
38 'username': 'actor_name',
39 'username': 'actor_name',
General Comments 0
You need to be logged in to leave comments. Login now