Show More
@@ -115,9 +115,7 b' class EEIntegration(IntegrationTypeBase)' | |||||
115 |
|
115 | |||
116 |
|
116 | |||
117 | # Helpers # |
|
117 | # Helpers # | |
118 |
|
118 | WEBHOOK_URL_VARS = [ | ||
119 | # common vars for url template |
|
|||
120 | CI_URL_VARS = [ |
|
|||
121 | ('event_name', 'Unique name of the event type, e.g pullrequest-update'), |
|
119 | ('event_name', 'Unique name of the event type, e.g pullrequest-update'), | |
122 | ('repo_name', 'Full name of the repository'), |
|
120 | ('repo_name', 'Full name of the repository'), | |
123 | ('repo_type', 'VCS type of repository'), |
|
121 | ('repo_type', 'VCS type of repository'), | |
@@ -140,6 +138,9 b' CI_URL_VARS = [' | |||||
140 | ('user_id', 'User id who triggered the call.'), |
|
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 | def get_auth(settings): |
|
145 | def get_auth(settings): | |
145 | from requests.auth import HTTPBasicAuth |
|
146 | from requests.auth import HTTPBasicAuth | |
@@ -151,4 +152,6 b' def get_auth(settings):' | |||||
151 |
|
152 | |||
152 |
|
153 | |||
153 | def get_url_vars(url_vars): |
|
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 | from rhodecode import events |
|
34 | from rhodecode import events | |
35 | from rhodecode.translation import _ |
|
35 | from rhodecode.translation import _ | |
36 | from rhodecode.integrations.types.base import ( |
|
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 | from rhodecode.lib.celerylib import run_task, async_task, RequestContextTask |
|
38 | from rhodecode.lib.celerylib import run_task, async_task, RequestContextTask | |
|
39 | from rhodecode.model.validation_schema import widgets | |||
39 |
|
40 | |||
40 | log = logging.getLogger(__name__) |
|
41 | log = logging.getLogger(__name__) | |
41 |
|
42 | |||
42 |
|
43 | |||
43 | # updating this required to update the `common_vars` passed in url calling func |
|
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 | URL_VARS = get_url_vars(WEBHOOK_URL_VARS) |
|
46 | URL_VARS = get_url_vars(WEBHOOK_URL_VARS) | |
67 |
|
47 | |||
68 |
|
48 | |||
@@ -178,17 +158,21 b' class WebhookSettingsSchema(colander.Sch' | |||||
178 | colander.String(), |
|
158 | colander.String(), | |
179 | title=_('Webhook URL'), |
|
159 | title=_('Webhook URL'), | |
180 | description= |
|
160 | description= | |
181 |
_('URL to which Webhook should submit data. |
|
161 | _('URL to which Webhook should submit data. If used some of the ' | |
182 | 'are allowed to be used: {vars}. Some of the variables would ' |
|
162 | 'variables would trigger multiple calls, like ${branch} or ' | |
183 | 'trigger multiple calls, like ${{branch}} or ${{commit_id}}. ' |
|
163 | '${commit_id}. Webhook will be called as many times as unique ' | |
184 | 'Webhook will be called as many times as unique objects in ' |
|
164 | 'objects in data in such cases.'), | |
185 | 'data in such cases.').format(vars=URL_VARS), |
|
|||
186 | missing=colander.required, |
|
165 | missing=colander.required, | |
187 | required=True, |
|
166 | required=True, | |
188 | validator=colander.url, |
|
167 | validator=colander.url, | |
189 |
widget= |
|
168 | widget=widgets.CodeMirrorWidget( | |
190 | placeholder='https://www.example.com/webhook' |
|
169 | help_block_collapsable_name='Show url variables', | |
191 | ), |
|
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 | secret_token = colander.SchemaNode( |
|
177 | secret_token = colander.SchemaNode( | |
194 | colander.String(), |
|
178 | colander.String(), | |
@@ -229,7 +213,7 b' class WebhookSettingsSchema(colander.Sch' | |||||
229 | default='', |
|
213 | default='', | |
230 | missing='', |
|
214 | missing='', | |
231 | widget=deform.widget.TextInputWidget( |
|
215 | widget=deform.widget.TextInputWidget( | |
232 |
placeholder='e.g |
|
216 | placeholder='e.g: Authorization' | |
233 | ), |
|
217 | ), | |
234 | ) |
|
218 | ) | |
235 | custom_header_val = colander.SchemaNode( |
|
219 | custom_header_val = colander.SchemaNode( | |
@@ -239,7 +223,7 b' class WebhookSettingsSchema(colander.Sch' | |||||
239 | default='', |
|
223 | default='', | |
240 | missing='', |
|
224 | missing='', | |
241 | widget=deform.widget.TextInputWidget( |
|
225 | widget=deform.widget.TextInputWidget( | |
242 |
placeholder='e.g. |
|
226 | placeholder='e.g. Basic XxXxXx' | |
243 | ), |
|
227 | ), | |
244 | ) |
|
228 | ) | |
245 | method_type = colander.SchemaNode( |
|
229 | method_type = colander.SchemaNode( |
@@ -5,6 +5,8 b'' | |||||
5 | name name|field.name; |
|
5 | name name|field.name; | |
6 | style style|field.widget.style; |
|
6 | style style|field.widget.style; | |
7 | help_block help_block|field.widget.help_block|''; |
|
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 | codemirror_options codemirror_options|field.widget.codemirror_options|{}; |
|
10 | codemirror_options codemirror_options|field.widget.codemirror_options|{}; | |
9 | codemirror_mode codemirror_mode|field.widget.codemirror_mode|'' |
|
11 | codemirror_mode codemirror_mode|field.widget.codemirror_mode|'' | |
10 | "> |
|
12 | "> | |
@@ -17,6 +19,9 b'' | |||||
17 | name="${name}">${cstruct}</textarea> |
|
19 | name="${name}">${cstruct}</textarea> | |
18 |
|
20 | |||
19 | <p tal:condition="help_block" class="help-block">${help_block}</p> |
|
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 | <script type="text/javascript"> |
|
25 | <script type="text/javascript"> | |
21 | deform.addCallback( |
|
26 | deform.addCallback( | |
22 | '${oid}', |
|
27 | '${oid}', |
General Comments 0
You need to be logged in to leave comments.
Login now