Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(291)

Side by Side Diff: gatekeeper_mailer.py

Issue 19878007: Add build mailer capability to support gatekeeper_ng. (Closed) Base URL: https://chromium.googlesource.com/chromium/tools/chromium-build@master
Patch Set: Rebase to latest master Created 7 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « app_test.py ('k') | mailer.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 #!/usr/bin/env python
2 # Copyright (c) 2013 The Chromium Authors. All rights reserved.
3 # Use of this source code is governed by a BSD-style license that can be
4 # found in the LICENSE file.
5
6 """Provides mailer templates for gatekeeper_ng.
7
8 This module populates jinja mail templates to notify tree watchers when the
9 tree is closed.
10 """
11
12 import jinja2
13 import os
14 import utils
15
16 jinja_environment = jinja2.Environment(
17 loader=jinja2.FileSystemLoader(
18 os.path.join(os.path.dirname(__file__), 'templates')),
19 autoescape=True)
20 jinja_environment.filters['urlquote'] = utils.urlquote
21
22 # From buildbot's results.py.
23 SUCCESS, WARNINGS, FAILURE, SKIPPED, EXCEPTION, RETRY = range(6)
24 Results = ["success", "warnings", "failure", "skipped", "exception", "retry"]
25
26
27 class MailTemplate(object):
28 """Encapsulates a buildbot status email."""
29
30 status_header = 'Automatically closing tree for "%(steps)s" on "%(builder)s"'
31
32 def __init__(self, waterfall_url, build_url,
33 project_name,
34 fromaddr,
35 reply_to=None,
36 subject='buildbot %(result)s in %(projectName)s on %(builder)s, '
37 'revision %(revision)s'):
38
39 self.reply_to = reply_to
40 self.fromaddr = fromaddr
41 self.subject = subject
42 self.waterfall_url = waterfall_url.rstrip('/') + '/'
43 self.build_url = build_url
44 self.project_name = project_name
45
46 def genMessageContent(self, build_status):
47 builder_name = build_status['builderName']
48 us_steps = ','.join(build_status['unsatisfied'])
49 revisions_list = build_status['revisions']
50 status_text = self.status_header % {
51 'builder': builder_name,
52 'steps': us_steps,
53 }
54
55 # Use the first line as a title.
56 status_title = status_text.split('\n', 1)[0]
57 blame_list = ','.join(build_status['blamelist'])
58 revisions_string = ''
59 latest_revision = 0
60 if revisions_list:
61 revisions_string = ', '.join([str(rev) for rev in revisions_list])
62 latest_revision = max([rev for rev in revisions_list])
63 if build_status['result'] == FAILURE:
64 result = 'failure'
65 else:
66 result = 'warning'
67
68 context = {
69 'status_title': status_title,
70 'waterfall_url': self.waterfall_url,
71 'status': status_text.replace('\n', "<br>\n"),
72 'build_url': self.build_url,
73 'revisions': revisions_string,
74 'blame_list': blame_list,
75 'build_status': build_status,
76 'builder_name': builder_name,
77 }
78
79 html_content = jinja_environment.get_template('waterfall_mail.html').render(
80 context)
81
82 text_content = jinja_environment.get_template('mail_text.txt').render(
83 context)
84
85 subject = self.subject % {
86 'result': result,
87 'projectName': self.project_name,
88 'builder': builder_name,
89 'reason': build_status['reason'],
90 'revision': str(latest_revision),
91 'buildnumber': str(build_status['number']),
92 }
93
94 return text_content, html_content, subject
OLDNEW
« no previous file with comments | « app_test.py ('k') | mailer.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698