##// END OF EJS Templates
webhook: use textarea and format url vars better for webhook integration....
marcink -
r2584:b8f98b31 default
parent child Browse files
Show More
@@ -115,9 +115,7 b' class EEIntegration(IntegrationTypeBase)'
115 115
116 116
117 117 # Helpers #
118
119 # common vars for url template
120 CI_URL_VARS = [
118 WEBHOOK_URL_VARS = [
121 119 ('event_name', 'Unique name of the event type, e.g pullrequest-update'),
122 120 ('repo_name', 'Full name of the repository'),
123 121 ('repo_type', 'VCS type of repository'),
@@ -140,6 +138,9 b' CI_URL_VARS = ['
140 138 ('user_id', 'User id who triggered the call.'),
141 139 ]
142 140
141 # common vars for url template used for CI plugins. Shared with webhook
142 CI_URL_VARS = WEBHOOK_URL_VARS
143
143 144
144 145 def get_auth(settings):
145 146 from requests.auth import HTTPBasicAuth
@@ -151,4 +152,6 b' def get_auth(settings):'
151 152
152 153
153 154 def get_url_vars(url_vars):
154 return ', '.join('${' + key + '}' for key, explanation in url_vars)
155 return '\n'.join(
156 '{} - {}'.format('${' + key + '}', explanation)
157 for key, explanation in url_vars)
@@ -34,35 +34,15 b' import rhodecode'
34 34 from rhodecode import events
35 35 from rhodecode.translation import _
36 36 from rhodecode.integrations.types.base import (
37 IntegrationTypeBase, get_auth, get_url_vars)
37 IntegrationTypeBase, get_auth, get_url_vars, WEBHOOK_URL_VARS)
38 38 from rhodecode.lib.celerylib import run_task, async_task, RequestContextTask
39 from rhodecode.model.validation_schema import widgets
39 40
40 41 log = logging.getLogger(__name__)
41 42
42 43
43 44 # updating this required to update the `common_vars` passed in url calling func
44 WEBHOOK_URL_VARS = [
45 ('event_name', 'Unique name of the event type, e.g pullrequest-update'),
46 ('repo_name', 'Full name of the repository'),
47 ('repo_type', 'VCS type of repository'),
48 ('repo_id', 'Unique id of repository'),
49 ('repo_url', 'Repository url'),
50 # extra repo fields
51 ('extra:<extra_key_name>', 'Extra repo variables, read from its settings.'),
52 45
53 # special attrs below that we handle, using multi-call
54 ('branch', 'Name of each brach submitted, if any.'),
55 ('commit_id', 'Id of each commit submitted, if any.'),
56
57 # pr events vars
58 ('pull_request_id', 'Unique ID of the pull request.'),
59 ('pull_request_url', 'Pull request url.'),
60 ('pull_request_shadow_url', 'Pull request shadow repo clone url.'),
61
62 # user who triggers the call
63 ('username', 'User who triggered the call.'),
64 ('user_id', 'User id who triggered the call.'),
65 ]
66 46 URL_VARS = get_url_vars(WEBHOOK_URL_VARS)
67 47
68 48
@@ -178,17 +158,21 b' class WebhookSettingsSchema(colander.Sch'
178 158 colander.String(),
179 159 title=_('Webhook URL'),
180 160 description=
181 _('URL to which Webhook should submit data. Following variables '
182 'are allowed to be used: {vars}. Some of the variables would '
183 'trigger multiple calls, like ${{branch}} or ${{commit_id}}. '
184 'Webhook will be called as many times as unique objects in '
185 'data in such cases.').format(vars=URL_VARS),
161 _('URL to which Webhook should submit data. If used some of the '
162 'variables would trigger multiple calls, like ${branch} or '
163 '${commit_id}. Webhook will be called as many times as unique '
164 'objects in data in such cases.'),
186 165 missing=colander.required,
187 166 required=True,
188 167 validator=colander.url,
189 widget=deform.widget.TextInputWidget(
190 placeholder='https://www.example.com/webhook'
191 ),
168 widget=widgets.CodeMirrorWidget(
169 help_block_collapsable_name='Show url variables',
170 help_block_collapsable=(
171 'E.g http://my-serv/trigger_job/${{event_name}}'
172 '?PR_ID=${{pull_request_id}}'
173 '\nFull list of vars:\n{}'.format(URL_VARS)),
174 codemirror_mode='text',
175 codemirror_options='{"lineNumbers": false, "lineWrapping": true}'),
192 176 )
193 177 secret_token = colander.SchemaNode(
194 178 colander.String(),
@@ -229,7 +213,7 b' class WebhookSettingsSchema(colander.Sch'
229 213 default='',
230 214 missing='',
231 215 widget=deform.widget.TextInputWidget(
232 placeholder='e.g.Authorization'
216 placeholder='e.g: Authorization'
233 217 ),
234 218 )
235 219 custom_header_val = colander.SchemaNode(
@@ -239,7 +223,7 b' class WebhookSettingsSchema(colander.Sch'
239 223 default='',
240 224 missing='',
241 225 widget=deform.widget.TextInputWidget(
242 placeholder='e.g. RcLogin auth=xxxx'
226 placeholder='e.g. Basic XxXxXx'
243 227 ),
244 228 )
245 229 method_type = colander.SchemaNode(
@@ -5,6 +5,8 b''
5 5 name name|field.name;
6 6 style style|field.widget.style;
7 7 help_block help_block|field.widget.help_block|'';
8 help_block_collapsable_name help_block_collapsable_name|field.widget.help_block_collapsable_name|'';
9 help_block_collapsable help_block_collapsable|field.widget.help_block_collapsable|'';
8 10 codemirror_options codemirror_options|field.widget.codemirror_options|{};
9 11 codemirror_mode codemirror_mode|field.widget.codemirror_mode|''
10 12 ">
@@ -17,6 +19,9 b''
17 19 name="${name}">${cstruct}</textarea>
18 20
19 21 <p tal:condition="help_block" class="help-block">${help_block}</p>
22 <span tal:condition="help_block_collapsable" class="help-block pre-formatting"><a href="#showVars" onclick="$('#help_block_${oid}').toggle(); return false">${help_block_collapsable_name}</a>
23 <p id="help_block_${oid}" style="display: none">${help_block_collapsable}</p>
24 </span>
20 25 <script type="text/javascript">
21 26 deform.addCallback(
22 27 '${oid}',
General Comments 0
You need to be logged in to leave comments. Login now