# -*- coding: utf-8 -*-
# Copyright (C) 2012-2018 RhodeCode GmbH
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License, version 3
# (only), as published by the Free Software Foundation.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see
|
${'This is a notification from RhodeCode. %(instance_url)s' % {'instance_url': instance_url}}
''') class EmailSettingsSchema(colander.Schema): @colander.instantiate(validator=colander.Length(min=1)) class recipients(colander.SequenceSchema): title = _('Recipients') description = _('Email addresses to send push events to') widget = deform.widget.SequenceWidget(min_len=1) recipient = colander.SchemaNode( colander.String(), title=_('Email address'), description=_('Email address'), default='', validator=colander.Email(), widget=deform.widget.TextInputWidget( placeholder='user@domain.com', ), ) class EmailIntegrationType(IntegrationTypeBase): key = 'email' display_name = _('Email') description = _('Send repo push summaries to a list of recipients via email') @classmethod def icon(cls): return ''' ''' def settings_schema(self): schema = EmailSettingsSchema() return schema def send_event(self, event): data = event.as_dict() log.debug('got event: %r', event) if isinstance(event, events.RepoPushEvent): repo_push_handler(data, self.settings) else: log.debug('ignoring event: %r', event) def repo_push_handler(data, settings): commit_num = len(data['push']['commits']) server_url = data['server_url'] if commit_num == 1: if data['push']['branches']: _subject = '[{repo_name}] {author} pushed {commit_num} commit on branches: {branches}' else: _subject = '[{repo_name}] {author} pushed {commit_num} commit' subject = _subject.format( author=data['actor']['username'], repo_name=data['repo']['repo_name'], commit_num=commit_num, branches=', '.join( branch['name'] for branch in data['push']['branches']) ) else: if data['push']['branches']: _subject = '[{repo_name}] {author} pushed {commit_num} commits on branches: {branches}' else: _subject = '[{repo_name}] {author} pushed {commit_num} commits' subject = _subject.format( author=data['actor']['username'], repo_name=data['repo']['repo_name'], commit_num=commit_num, branches=', '.join( branch['name'] for branch in data['push']['branches'])) email_body_plaintext = render_with_traceback( REPO_PUSH_TEMPLATE_PLAINTEXT, data=data, subject=subject, instance_url=server_url) email_body_html = render_with_traceback( REPO_PUSH_TEMPLATE_HTML, data=data, subject=subject, instance_url=server_url) for email_address in settings['recipients']: run_task( tasks.send_email, email_address, subject, email_body_plaintext, email_body_html)