##// END OF EJS Templates
integrations: added safe renderers with detailed traceback information.
dan -
r2646:f61fee89 default
parent child Browse files
Show More
@@ -22,8 +22,12 b' import colander'
22 import string
22 import string
23 import collections
23 import collections
24 import logging
24 import logging
25
26 from mako import exceptions
27
25 from rhodecode.translation import _
28 from rhodecode.translation import _
26
29
30
27 log = logging.getLogger(__name__)
31 log = logging.getLogger(__name__)
28
32
29
33
@@ -297,3 +301,11 b' def get_url_vars(url_vars):'
297 return '\n'.join(
301 return '\n'.join(
298 '{} - {}'.format('${' + key + '}', explanation)
302 '{} - {}'.format('${' + key + '}', explanation)
299 for key, explanation in url_vars)
303 for key, explanation in url_vars)
304
305
306 def render_with_traceback(template, *args, **kwargs):
307 try:
308 return template.render(*args, **kwargs)
309 except Exception:
310 log.error(exceptions.text_error_template().render())
311 raise
@@ -29,7 +29,8 b' from rhodecode import events'
29 from rhodecode.translation import _
29 from rhodecode.translation import _
30 from rhodecode.lib.celerylib import run_task
30 from rhodecode.lib.celerylib import run_task
31 from rhodecode.lib.celerylib import tasks
31 from rhodecode.lib.celerylib import tasks
32 from rhodecode.integrations.types.base import IntegrationTypeBase
32 from rhodecode.integrations.types.base import (
33 IntegrationTypeBase, render_with_traceback)
33
34
34
35
35 log = logging.getLogger(__name__)
36 log = logging.getLogger(__name__)
@@ -281,12 +282,14 b' def repo_push_handler(data, settings):'
281 branches=', '.join(
282 branches=', '.join(
282 branch['name'] for branch in data['push']['branches']))
283 branch['name'] for branch in data['push']['branches']))
283
284
284 email_body_plaintext = repo_push_template_plaintext.render(
285 email_body_plaintext = render_with_traceback(
286 repo_push_template_plaintext,
285 data=data,
287 data=data,
286 subject=subject,
288 subject=subject,
287 instance_url=server_url)
289 instance_url=server_url)
288
290
289 email_body_html = repo_push_template_html.render(
291 email_body_html = render_with_traceback(
292 repo_push_template_html,
290 data=data,
293 data=data,
291 subject=subject,
294 subject=subject,
292 instance_url=server_url)
295 instance_url=server_url)
@@ -31,7 +31,7 b' from rhodecode.lib import helpers as h'
31 from rhodecode.lib.celerylib import run_task, async_task, RequestContextTask
31 from rhodecode.lib.celerylib import run_task, async_task, RequestContextTask
32 from rhodecode.lib.colander_utils import strip_whitespace
32 from rhodecode.lib.colander_utils import strip_whitespace
33 from rhodecode.integrations.types.base import (
33 from rhodecode.integrations.types.base import (
34 IntegrationTypeBase, CommitParsingDataHandler)
34 IntegrationTypeBase, CommitParsingDataHandler, render_with_traceback)
35
35
36 log = logging.getLogger(__name__)
36 log = logging.getLogger(__name__)
37
37
@@ -220,7 +220,8 b' class HipchatIntegrationType(Integration'
220 branches_commits = self.aggregate_branch_data(
220 branches_commits = self.aggregate_branch_data(
221 data['push']['branches'], data['push']['commits'])
221 data['push']['branches'], data['push']['commits'])
222
222
223 result = repo_push_template.render(
223 result = render_with_traceback(
224 repo_push_template,
224 data=data,
225 data=data,
225 branches_commits=branches_commits,
226 branches_commits=branches_commits,
226 )
227 )
@@ -35,7 +35,7 b' from rhodecode.lib import helpers as h'
35 from rhodecode.lib.celerylib import run_task, async_task, RequestContextTask
35 from rhodecode.lib.celerylib import run_task, async_task, RequestContextTask
36 from rhodecode.lib.colander_utils import strip_whitespace
36 from rhodecode.lib.colander_utils import strip_whitespace
37 from rhodecode.integrations.types.base import (
37 from rhodecode.integrations.types.base import (
38 IntegrationTypeBase, CommitParsingDataHandler)
38 IntegrationTypeBase, CommitParsingDataHandler, render_with_traceback)
39
39
40 log = logging.getLogger(__name__)
40 log = logging.getLogger(__name__)
41
41
@@ -194,32 +194,39 b' class SlackIntegrationType(IntegrationTy'
194 }
194 }
195 ]
195 ]
196
196
197 title = Template(textwrap.dedent(r'''
197 template = Template(textwrap.dedent(r'''
198 *${data['actor']['username']}* left ${data['comment']['type']} on pull request <${data['pullrequest']['url']}|#${data['pullrequest']['pull_request_id']}>:
198 *${data['actor']['username']}* left ${data['comment']['type']} on pull request <${data['pullrequest']['url']}|#${data['pullrequest']['pull_request_id']}>:
199 ''')).render(data=data, comment=event.comment)
199 '''))
200 title = render_with_traceback(
201 template, data=data, comment=event.comment)
200
202
201 text = Template(textwrap.dedent(r'''
203 template = Template(textwrap.dedent(r'''
202 *pull request title*: ${pr_title}
204 *pull request title*: ${pr_title}
203 % if status_text:
205 % if status_text:
204 *submitted status*: `${status_text}`
206 *submitted status*: `${status_text}`
205 % endif
207 % endif
206 >>> ${comment_text}
208 >>> ${comment_text}
207 ''')).render(comment_text=comment_text,
209 '''))
208 pr_title=data['pullrequest']['title'],
210 text = render_with_traceback(
209 status_text=status_text)
211 template,
212 comment_text=comment_text,
213 pr_title=data['pullrequest']['title'],
214 status_text=status_text)
210
215
211 return title, text, fields, overrides
216 return title, text, fields, overrides
212
217
213 def format_pull_request_review_event(self, event, data):
218 def format_pull_request_review_event(self, event, data):
214 title = Template(textwrap.dedent(r'''
219 template = Template(textwrap.dedent(r'''
215 *${data['actor']['username']}* changed status of pull request <${data['pullrequest']['url']}|#${data['pullrequest']['pull_request_id']} to `${data['pullrequest']['status']}`>:
220 *${data['actor']['username']}* changed status of pull request <${data['pullrequest']['url']}|#${data['pullrequest']['pull_request_id']} to `${data['pullrequest']['status']}`>:
216 ''')).render(data=data)
221 '''))
222 title = render_with_traceback(template, data=data)
217
223
218 text = Template(textwrap.dedent(r'''
224 template = Template(textwrap.dedent(r'''
219 *pull request title*: ${pr_title}
225 *pull request title*: ${pr_title}
220 ''')).render(
226 '''))
221 pr_title=data['pullrequest']['title'],
227 text = render_with_traceback(
222 )
228 template,
229 pr_title=data['pullrequest']['title'])
223
230
224 return title, text
231 return title, text
225
232
@@ -231,19 +238,21 b' class SlackIntegrationType(IntegrationTy'
231 events.PullRequestCreateEvent: 'created',
238 events.PullRequestCreateEvent: 'created',
232 }.get(event.__class__, str(event.__class__))
239 }.get(event.__class__, str(event.__class__))
233
240
234 title = Template(textwrap.dedent(r'''
241 template = Template(textwrap.dedent(r'''
235 *${data['actor']['username']}* `${action}` pull request <${data['pullrequest']['url']}|#${data['pullrequest']['pull_request_id']}>:
242 *${data['actor']['username']}* `${action}` pull request <${data['pullrequest']['url']}|#${data['pullrequest']['pull_request_id']}>:
236 ''')).render(data=data, action=action)
243 '''))
244 title = render_with_traceback(template, data=data, action=action)
237
245
238 text = Template(textwrap.dedent(r'''
246 template = Template(textwrap.dedent(r'''
239 *pull request title*: ${pr_title}
247 *pull request title*: ${pr_title}
240 %if data['pullrequest']['commits']:
248 %if data['pullrequest']['commits']:
241 *commits*: ${len(data['pullrequest']['commits'])}
249 *commits*: ${len(data['pullrequest']['commits'])}
242 %endif
250 %endif
243 ''')).render(
251 '''))
252 text = render_with_traceback(
253 template,
244 pr_title=data['pullrequest']['title'],
254 pr_title=data['pullrequest']['title'],
245 data=data
255 data=data)
246 )
247
256
248 return title, text
257 return title, text
249
258
@@ -252,9 +261,10 b' class SlackIntegrationType(IntegrationTy'
252 branches_commits = self.aggregate_branch_data(
261 branches_commits = self.aggregate_branch_data(
253 data['push']['branches'], data['push']['commits'])
262 data['push']['branches'], data['push']['commits'])
254
263
255 title = Template(r'''
264 template = Template(r'''
256 *${data['actor']['username']}* pushed to repo <${data['repo']['url']}|${data['repo']['repo_name']}>:
265 *${data['actor']['username']}* pushed to repo <${data['repo']['url']}|${data['repo']['repo_name']}>:
257 ''').render(data=data)
266 ''')
267 title = render_with_traceback(template, data=data)
258
268
259 repo_push_template = Template(textwrap.dedent(r'''
269 repo_push_template = Template(textwrap.dedent(r'''
260 %for branch, branch_commits in branches_commits.items():
270 %for branch, branch_commits in branches_commits.items():
@@ -265,7 +275,8 b' class SlackIntegrationType(IntegrationTy'
265 %endfor
275 %endfor
266 '''))
276 '''))
267
277
268 text = repo_push_template.render(
278 text = render_with_traceback(
279 repo_push_template,
269 data=data,
280 data=data,
270 branches_commits=branches_commits,
281 branches_commits=branches_commits,
271 html_to_slack_links=html_to_slack_links,
282 html_to_slack_links=html_to_slack_links,
@@ -274,14 +285,16 b' class SlackIntegrationType(IntegrationTy'
274 return title, text
285 return title, text
275
286
276 def format_repo_create_event(self, data):
287 def format_repo_create_event(self, data):
277 title = Template(r'''
288 template = Template(r'''
278 *${data['actor']['username']}* created new repository ${data['repo']['repo_name']}:
289 *${data['actor']['username']}* created new repository ${data['repo']['repo_name']}:
279 ''').render(data=data)
290 ''')
291 title = render_with_traceback(template, data=data)
280
292
281 text = Template(textwrap.dedent(r'''
293 template = Template(textwrap.dedent(r'''
282 repo_url: ${data['repo']['url']}
294 repo_url: ${data['repo']['url']}
283 repo_type: ${data['repo']['repo_type']}
295 repo_type: ${data['repo']['repo_type']}
284 ''')).render(data=data)
296 '''))
297 text = render_with_traceback(template, data=data)
285
298
286 return title, text
299 return title, text
287
300
General Comments 0
You need to be logged in to leave comments. Login now