def send(self, job, parent=None): # TODO(dcramer): we should send a clipping of a relevant job log recipients = self.get_recipients(job) if not recipients: return event = try_create(Event, where={ 'type': EventType.email, 'item_id': job.build_id, 'data': { 'recipients': recipients, } }) if not event: # We've already sent out notifications for this build return context = self.get_context(job, parent) msg = Message(context['title'], recipients=recipients, extra_headers={ 'Reply-To': ', '.join(sanitize_address(r) for r in recipients), }) msg.body = render_template('listeners/mail/notification.txt', **context) msg.html = Markup(toronado.from_string( render_template('listeners/mail/notification.html', **context) )) mail.send(msg)
def send(self, job, parent=None): # TODO(dcramer): we should send a clipping of a relevant job log recipients = self.get_recipients(job) if not recipients: return event = try_create(Event, where={ 'type': EventType.email, 'item_id': job.build_id, 'data': { 'recipients': recipients, } }) if not event: # We've already sent out notifications for this build return context = self.get_context(job, parent) msg = Message(context['title'], recipients=recipients, extra_headers={ 'Reply-To': ', '.join(sanitize_address(r) for r in recipients), }) msg.body = render_template('listeners/mail/notification.txt', **context) msg.html = Markup( toronado.from_string( render_template('listeners/mail/notification.html', **context))) mail.send(msg)
def send(self, msg, build): msg.recipients = filter_recipients(msg.recipients) if not msg.recipients: self.logger.info( 'Exiting for collection_id={} because its message has no ' 'recipients.'.format(build.collection_id)) return event = try_create(Event, where={ 'type': EventType.email, 'item_id': build.collection_id, 'data': { 'triggering_build_id': build.id.hex, 'recipients': msg.recipients, } }) # If we were unable to create the Event, we must've done so (and thus sent the mail) already. if not event: self.logger.warning( 'An email has already been sent for collection_id=%s, (build_id=%s).', build.collection_id, build.id.hex) return mail.send(msg)
def send_notification(job, recipients): # TODO(dcramer): we should send a clipping of a relevant job log test_failures = TestGroup.query.filter( TestGroup.job_id == job.id, TestGroup.result == Result.failed, TestGroup.num_leaves == 0, ).order_by(TestGroup.name.asc()) num_test_failures = test_failures.count() test_failures = test_failures[:25] build = job.build # TODO(dcramer): we should probably find a better way to do logs primary_log = LogSource.query.filter( LogSource.job_id == job.id, ).order_by(LogSource.date_created.asc()).first() if primary_log: log_clipping = get_log_clipping( primary_log, max_size=5000, max_lines=25) subject = u"Build {result} - {project} #{number} ({target})".format( number='{0}.{1}'.format(job.build.number, job.number), result=unicode(job.result), target=build.target or build.source.revision_sha or 'Unknown', project=job.project.name, ) for testgroup in test_failures: testgroup.uri = build_uri('/testgroups/{0}/'.format(testgroup.id.hex)) job.uri = build_uri('/jobs/{0}/'.format(job.id.hex)) build.uri = build_uri('/builds/{0}/'.format(build.id.hex)) context = { 'job': job, 'build': job.build, 'total_test_failures': num_test_failures, 'test_failures': test_failures, } if primary_log: context['build_log'] = { 'text': log_clipping, 'name': primary_log.name, 'link': '{0}logs/{1}/'.format(job.uri, primary_log.id.hex), } msg = Message(subject, recipients=recipients, extra_headers={ 'Reply-To': ', '.join(sanitize_address(r) for r in recipients), }) msg.body = render_template('listeners/mail/notification.txt', **context) msg.html = render_template('listeners/mail/notification.html', **context) mail.send(msg)
def send(self, job, parent=None): # TODO(dcramer): we should send a clipping of a relevant job log recipients = self.get_recipients(job) if not recipients: return context = self.get_context(job, parent) msg = Message(context['title'], recipients=recipients, extra_headers={ 'Reply-To': ', '.join(sanitize_address(r) for r in recipients), }) msg.body = render_template('listeners/mail/notification.txt', **context) msg.html = Markup(Pynliner().from_string( render_template('listeners/mail/notification.html', **context) ).run()) mail.send(msg)
def send(self, msg, build): if not msg.recipients: self.logger.info( 'Exiting for collection_id={} because its message has no ' 'recipients.'.format(build.collection_id)) return event = try_create(Event, where={ 'type': EventType.email, 'item_id': build.collection_id, 'data': { 'triggering_build_id': build.id.hex, 'recipients': msg.recipients, } }) # If we were unable to create the Event, we must've done so (and thus sent the mail) already. if not event: self.logger.warning('An email has already been sent for collection_id=%s, (build_id=%s).', build.collection_id, build.id.hex) return mail.send(msg)
def send(self, job, parent=None): # TODO(dcramer): we should send a clipping of a relevant job log recipients = filter_recipients(self.get_recipients(job)) if not recipients: return event = try_create( Event, where={"type": EventType.email, "item_id": job.build_id, "data": {"recipients": recipients}} ) if not event: # We've already sent out notifications for this build return context = self.get_context(job, parent) msg = Message( context["title"], recipients=recipients, extra_headers={"Reply-To": ", ".join(sanitize_address(r) for r in recipients)}, ) msg.body = render_template("listeners/mail/notification.txt", **context) msg.html = Markup(toronado.from_string(render_template("listeners/mail/notification.html", **context))) mail.send(msg)