##// 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 22 import string
23 23 import collections
24 24 import logging
25
26 from mako import exceptions
27
25 28 from rhodecode.translation import _
26 29
30
27 31 log = logging.getLogger(__name__)
28 32
29 33
@@ -297,3 +301,11 b' def get_url_vars(url_vars):'
297 301 return '\n'.join(
298 302 '{} - {}'.format('${' + key + '}', explanation)
299 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 29 from rhodecode.translation import _
30 30 from rhodecode.lib.celerylib import run_task
31 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 36 log = logging.getLogger(__name__)
@@ -281,12 +282,14 b' def repo_push_handler(data, settings):'
281 282 branches=', '.join(
282 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 287 data=data,
286 288 subject=subject,
287 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 293 data=data,
291 294 subject=subject,
292 295 instance_url=server_url)
@@ -31,7 +31,7 b' from rhodecode.lib import helpers as h'
31 31 from rhodecode.lib.celerylib import run_task, async_task, RequestContextTask
32 32 from rhodecode.lib.colander_utils import strip_whitespace
33 33 from rhodecode.integrations.types.base import (
34 IntegrationTypeBase, CommitParsingDataHandler)
34 IntegrationTypeBase, CommitParsingDataHandler, render_with_traceback)
35 35
36 36 log = logging.getLogger(__name__)
37 37
@@ -220,7 +220,8 b' class HipchatIntegrationType(Integration'
220 220 branches_commits = self.aggregate_branch_data(
221 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 225 data=data,
225 226 branches_commits=branches_commits,
226 227 )
@@ -35,7 +35,7 b' from rhodecode.lib import helpers as h'
35 35 from rhodecode.lib.celerylib import run_task, async_task, RequestContextTask
36 36 from rhodecode.lib.colander_utils import strip_whitespace
37 37 from rhodecode.integrations.types.base import (
38 IntegrationTypeBase, CommitParsingDataHandler)
38 IntegrationTypeBase, CommitParsingDataHandler, render_with_traceback)
39 39
40 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 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 204 *pull request title*: ${pr_title}
203 205 % if status_text:
204 206 *submitted status*: `${status_text}`
205 207 % endif
206 208 >>> ${comment_text}
207 ''')).render(comment_text=comment_text,
208 pr_title=data['pullrequest']['title'],
209 status_text=status_text)
209 '''))
210 text = render_with_traceback(
211 template,
212 comment_text=comment_text,
213 pr_title=data['pullrequest']['title'],
214 status_text=status_text)
210 215
211 216 return title, text, fields, overrides
212 217
213 218 def format_pull_request_review_event(self, event, data):
214 title = Template(textwrap.dedent(r'''
219 template = Template(textwrap.dedent(r'''
215 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 225 *pull request title*: ${pr_title}
220 ''')).render(
221 pr_title=data['pullrequest']['title'],
222 )
226 '''))
227 text = render_with_traceback(
228 template,
229 pr_title=data['pullrequest']['title'])
223 230
224 231 return title, text
225 232
@@ -231,19 +238,21 b' class SlackIntegrationType(IntegrationTy'
231 238 events.PullRequestCreateEvent: 'created',
232 239 }.get(event.__class__, str(event.__class__))
233 240
234 title = Template(textwrap.dedent(r'''
241 template = Template(textwrap.dedent(r'''
235 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 247 *pull request title*: ${pr_title}
240 248 %if data['pullrequest']['commits']:
241 249 *commits*: ${len(data['pullrequest']['commits'])}
242 250 %endif
243 ''')).render(
251 '''))
252 text = render_with_traceback(
253 template,
244 254 pr_title=data['pullrequest']['title'],
245 data=data
246 )
255 data=data)
247 256
248 257 return title, text
249 258
@@ -252,9 +261,10 b' class SlackIntegrationType(IntegrationTy'
252 261 branches_commits = self.aggregate_branch_data(
253 262 data['push']['branches'], data['push']['commits'])
254 263
255 title = Template(r'''
264 template = Template(r'''
256 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 269 repo_push_template = Template(textwrap.dedent(r'''
260 270 %for branch, branch_commits in branches_commits.items():
@@ -265,7 +275,8 b' class SlackIntegrationType(IntegrationTy'
265 275 %endfor
266 276 '''))
267 277
268 text = repo_push_template.render(
278 text = render_with_traceback(
279 repo_push_template,
269 280 data=data,
270 281 branches_commits=branches_commits,
271 282 html_to_slack_links=html_to_slack_links,
@@ -274,14 +285,16 b' class SlackIntegrationType(IntegrationTy'
274 285 return title, text
275 286
276 287 def format_repo_create_event(self, data):
277 title = Template(r'''
288 template = Template(r'''
278 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 294 repo_url: ${data['repo']['url']}
283 295 repo_type: ${data['repo']['repo_type']}
284 ''')).render(data=data)
296 '''))
297 text = render_with_traceback(template, data=data)
285 298
286 299 return title, text
287 300
General Comments 0
You need to be logged in to leave comments. Login now