Skip to content

Commit

Permalink
MessageFormatter: allow to extend the context given to the template
Browse files Browse the repository at this point in the history
  • Loading branch information
Benoît Allard committed Oct 25, 2016
1 parent 6c691f5 commit dd114c3
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions master/buildbot/reporters/message.py
Expand Up @@ -35,7 +35,7 @@ class MessageFormatter(object):
wantLogs = False

def __init__(self, template_name=None, template_dir=None, template=None,
subject_name=None, subject=None, template_type=None):
subject_name=None, subject=None, template_type=None, ctx=None):

if (template is not None) and ((template_name is not None) or (template_dir is not None)):
config.error("Only one of template or template path can be given")
Expand All @@ -48,6 +48,11 @@ def __init__(self, template_name=None, template_dir=None, template=None,
if template_type is not None:
self.template_type = template_type

if ctx is None:
ctx = {}

self.ctx = ctx


def getTemplate(self, filename, dirname, content):
if content and filename:
Expand Down Expand Up @@ -152,7 +157,7 @@ def __call__(self, mode, buildername, buildset, build, master, previous_results,
ss_list = buildset['sourcestamps']
results = build['results']

cxt = dict(results=build['results'],
ctx = dict(results=build['results'],
mode=mode,
buildername=buildername,
workername=build['properties'].get(
Expand All @@ -170,8 +175,9 @@ def __call__(self, mode, buildername, buildset, build, master, previous_results,
summary=self.messageSummary(build, results),
sourcestamps=self.messageSourceStamps(ss_list)
)
body = self.body_template.render(cxt)
ctx.update(self.ctx)
body = self.body_template.render(ctx)
email = {'body': body, 'type': self.template_type}
if self.subject_template is not None:
email['subject'] = self.subject_template.render(cxt)
email['subject'] = self.subject_template.render(ctx)
return email

0 comments on commit dd114c3

Please sign in to comment.