| OLD | NEW |
| 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 status_header = 'Automatically closing tree for "%(steps)s" on "%(builder)s"' |
| 31 default_subject = ('buildbot %(result)s in %(projectName)s on %(builder)s, ' |
| 32 'revision %(revision)s') |
| 31 | 33 |
| 32 def __init__(self, waterfall_url, build_url, | 34 def __init__(self, waterfall_url, build_url, project_name, fromaddr, |
| 33 project_name, | 35 reply_to=None, subject=None): |
| 34 fromaddr, | 36 |
| 35 reply_to=None, | |
| 36 subject='buildbot %(result)s in %(projectName)s on %(builder)s, ' | |
| 37 'revision %(revision)s'): | |
| 38 | 37 |
| 39 self.reply_to = reply_to | 38 self.reply_to = reply_to |
| 40 self.fromaddr = fromaddr | 39 self.fromaddr = fromaddr |
| 41 self.subject = subject | 40 self.subject = subject or self.default_subject |
| 42 self.waterfall_url = waterfall_url.rstrip('/') + '/' | 41 self.waterfall_url = waterfall_url.rstrip('/') + '/' |
| 43 self.build_url = build_url | 42 self.build_url = build_url |
| 44 self.project_name = project_name | 43 self.project_name = project_name |
| 45 | 44 |
| 46 def genMessageContent(self, build_status): | 45 def genMessageContent(self, build_status): |
| 47 builder_name = build_status['builderName'] | 46 builder_name = build_status['builderName'] |
| 48 us_steps = ','.join(build_status['unsatisfied']) | 47 us_steps = ','.join(build_status['unsatisfied']) |
| 49 revisions_list = build_status['revisions'] | 48 revisions_list = build_status['revisions'] |
| 50 status_text = self.status_header % { | 49 status_text = self.status_header % { |
| 51 'builder': builder_name, | 50 'builder': builder_name, |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 85 subject = self.subject % { | 84 subject = self.subject % { |
| 86 'result': result, | 85 'result': result, |
| 87 'projectName': self.project_name, | 86 'projectName': self.project_name, |
| 88 'builder': builder_name, | 87 'builder': builder_name, |
| 89 'reason': build_status['reason'], | 88 'reason': build_status['reason'], |
| 90 'revision': str(latest_revision), | 89 'revision': str(latest_revision), |
| 91 'buildnumber': str(build_status['number']), | 90 'buildnumber': str(build_status['number']), |
| 92 } | 91 } |
| 93 | 92 |
| 94 return text_content, html_content, subject | 93 return text_content, html_content, subject |
| OLD | NEW |