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

Side by Side Diff: gatekeeper_mailer.py

Issue 143263025: Add support to change the status header for gatekeeper-ng. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/tools/chromium-build
Patch Set: Rename to use status_header instead of status. Created 6 years, 10 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 | Annotate | Revision Log
« 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
1 #!/usr/bin/env python 1 #!/usr/bin/env python
2 # Copyright (c) 2013 The Chromium Authors. All rights reserved. 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 3 # Use of this source code is governed by a BSD-style license that can be
4 # found in the LICENSE file. 4 # found in the LICENSE file.
5 5
6 """Provides mailer templates for gatekeeper_ng. 6 """Provides mailer templates for gatekeeper_ng.
7 7
8 This module populates jinja mail templates to notify tree watchers when the 8 This module populates jinja mail templates to notify tree watchers when the
9 tree is closed. 9 tree is closed.
10 """ 10 """
11 11
12 import jinja2 12 import jinja2
13 import os 13 import os
14 import utils 14 import utils
15 15
16 jinja_environment = jinja2.Environment( 16 jinja_environment = jinja2.Environment(
17 loader=jinja2.FileSystemLoader( 17 loader=jinja2.FileSystemLoader(
18 os.path.join(os.path.dirname(__file__), 'templates')), 18 os.path.join(os.path.dirname(__file__), 'templates')),
19 autoescape=True) 19 autoescape=True)
20 jinja_environment.filters['urlquote'] = utils.urlquote 20 jinja_environment.filters['urlquote'] = utils.urlquote
21 21
22 # From buildbot's results.py. 22 # From buildbot's results.py.
23 SUCCESS, WARNINGS, FAILURE, SKIPPED, EXCEPTION, RETRY = range(6) 23 SUCCESS, WARNINGS, FAILURE, SKIPPED, EXCEPTION, RETRY = range(6)
24 Results = ["success", "warnings", "failure", "skipped", "exception", "retry"] 24 Results = ["success", "warnings", "failure", "skipped", "exception", "retry"]
25 25
26 26
27 class MailTemplate(object): 27 class MailTemplate(object):
28 """Encapsulates a buildbot status email.""" 28 """Encapsulates a buildbot status email."""
29 29
30 status_header = 'Automatically closing tree for "%(steps)s" on "%(builder)s"' 30 default_status_header = ('Automatically closing tree for "%(steps)s" on '
31 default_subject = ('buildbot %(result)s in %(projectName)s on %(builder)s, ' 31 '"%(builder_name)s"')
32 'revision %(revision)s') 32 default_subject = ('buildbot %(result)s in %(project_name)s on '
33 '%(builder_name)s, revision %(revision)s')
33 34
34 def __init__(self, waterfall_url, build_url, project_name, fromaddr, 35 def __init__(self, waterfall_url, build_url, project_name, fromaddr,
35 reply_to=None, subject=None): 36 reply_to=None, subject=None, status_header=None):
36 37
37 38
38 self.reply_to = reply_to 39 self.reply_to = reply_to
39 self.fromaddr = fromaddr 40 self.fromaddr = fromaddr
40 self.subject = subject or self.default_subject 41 self.subject = subject or self.default_subject
42 self.status_header = status_header or self.default_status_header
41 self.waterfall_url = waterfall_url 43 self.waterfall_url = waterfall_url
42 self.build_url = build_url 44 self.build_url = build_url
43 self.project_name = project_name 45 self.project_name = project_name
44 46
45 def genMessageContent(self, build_status): 47 def genMessageContent(self, build_status):
46 builder_name = build_status['builderName'] 48 builder_name = build_status['builderName']
47 us_steps = ','.join(build_status['unsatisfied']) 49 us_steps = ','.join(build_status['unsatisfied'])
48 revisions_list = build_status['revisions'] 50 revisions_list = build_status['revisions']
49 status_text = self.status_header % {
50 'builder': builder_name,
51 'steps': us_steps,
52 }
53
54 # Use the first line as a title.
55 status_title = status_text.split('\n', 1)[0]
56 blame_list = ','.join(build_status['blamelist']) 51 blame_list = ','.join(build_status['blamelist'])
57 revisions_string = '' 52 revisions_string = ''
58 latest_revision = 0 53 latest_revision = 0
59 if revisions_list: 54 if revisions_list:
60 revisions_string = ', '.join([str(rev) for rev in revisions_list]) 55 revisions_string = ', '.join([str(rev) for rev in revisions_list])
61 latest_revision = max([rev for rev in revisions_list]) 56 latest_revision = max([rev for rev in revisions_list])
62 if build_status['result'] == FAILURE: 57 if build_status['result'] == FAILURE:
63 result = 'failure' 58 result = 'failure'
64 else: 59 else:
65 result = 'warning' 60 result = 'warning'
66 61
67 context = { 62 context = {
68 'status_title': status_title,
69 'waterfall_url': self.waterfall_url,
70 'status': status_text.replace('\n', "<br>\n"),
71 'build_url': self.build_url,
72 'revisions': revisions_string,
73 'blame_list': blame_list, 63 'blame_list': blame_list,
74 'build_status': build_status, 64 'build_status': build_status,
65 'build_url': self.build_url,
75 'builder_name': builder_name, 66 'builder_name': builder_name,
67 'revisions': revisions_string,
68 'steps': us_steps,
69 'waterfall_url': self.waterfall_url,
76 } 70 }
77 71
72 status_text = self.status_header % context
73
74 # Use the first line as a title.
75 status_title = status_text.split('\n', 1)[0]
76
77 context['status'] = status_text.replace('\n', "<br>\n")
78 context['status_title'] = status_title
79
78 html_content = jinja_environment.get_template('waterfall_mail.html').render( 80 html_content = jinja_environment.get_template('waterfall_mail.html').render(
79 context) 81 context)
80 82
81 text_content = jinja_environment.get_template('mail_text.txt').render( 83 text_content = jinja_environment.get_template('mail_text.txt').render(
82 context) 84 context)
83 85
84 subject = self.subject % { 86 subject = self.subject % {
85 'result': result, 87 'result': result,
86 'projectName': self.project_name, 88 'project_name': self.project_name,
87 'builder': builder_name, 89 'builder_name': builder_name,
88 'reason': build_status['reason'], 90 'reason': build_status['reason'],
89 'revision': str(latest_revision), 91 'revision': str(latest_revision),
90 'buildnumber': str(build_status['number']), 92 'buildnumber': str(build_status['number']),
91 } 93 }
92 94
93 return text_content, html_content, subject 95 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