# HG changeset patch # User Marcin Kuzminski # Date 2016-08-12 00:59:29 # Node ID 6e54c5817b7a694d41bb0b7efa282c7af095eb53 # Parent 724715f171e26135e85bba86976326d176f6bf6b integrations: update emails integration with nicer emails diff --git a/rhodecode/integrations/types/email.py b/rhodecode/integrations/types/email.py --- a/rhodecode/integrations/types/email.py +++ b/rhodecode/integrations/types/email.py @@ -19,7 +19,6 @@ # and proprietary license terms, please see https://rhodecode.com/licenses/ from __future__ import unicode_literals - import deform import logging import colander @@ -34,8 +33,119 @@ from rhodecode.integrations.types.base i from rhodecode.integrations.schema import IntegrationSettingsSchemaBase -log = logging.getLogger() +log = logging.getLogger(__name__) + +repo_push_template_plaintext = Template(''' +Commits: + +% for commit in data['push']['commits']: +${commit['url']} by ${commit['author']} at ${commit['date']} +${commit['message']} +---- + +% endfor +''') + +## TODO (marcink): think about putting this into a file, or use base.mako email template + +repo_push_template_html = Template(''' + + + + + + ${subject} + + + + + + + + + + + + + +
+ + + + + +
+ + ${'RhodeCode'} + +
+ % for commit in data['push']['commits']: + ${commit['short_id']} by ${commit['author']} at ${commit['date']}
+ ${commit['message_html']}
+
+ % endfor +
+
+ +

+ ${'This is a notification from RhodeCode. %(instance_url)s' % {'instance_url': instance_url}} +

+ + +''') class EmailSettingsSchema(IntegrationSettingsSchemaBase): @@ -77,51 +187,36 @@ class EmailIntegrationType(IntegrationTy def repo_push_handler(data, settings): - for commit in data['push']['commits']: - email_body_plaintext = repo_push_template_plaintext.render( - data=data, - commit=commit, - commit_msg=commit['message'], - ) - email_body_html = repo_push_template_html.render( - data=data, - commit=commit, - commit_msg=commit['message_html'], - ) - - subject = '[%(repo_name)s] %(commit_id)s: %(commit_msg)s' % { - 'repo_name': data['repo']['repo_name'], - 'commit_id': commit['short_id'], - 'commit_msg': commit['message'].split('\n')[0][:150] - } - for email_address in settings['recipients']: - task = run_task( - tasks.send_email, email_address, subject, - email_body_plaintext, email_body_html) - + commit_num = len(data['push']['commits']) + server_url = data['server_url'] -# TODO: dan: add changed files, make html pretty -repo_push_template_plaintext = Template(''' -User: ${data['actor']['username']} -Branches: ${', '.join(branch['name'] for branch in data['push']['branches'])} -Repository: ${data['repo']['url']} -Commit: ${commit['raw_id']} -URL: ${commit['url']} -Author: ${commit['author']} -Date: ${commit['date']} -Commit Message: + if commit_num == 0: + subject = '[{repo_name}] {author} pushed {commit_num} commit on branches: {branches}'.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: + subject = '[{repo_name}] {author} pushed {commit_num} commits on branches: {branches}'.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'])) -${commit_msg} -''') + email_body_plaintext = repo_push_template_plaintext.render( + data=data, + subject=subject, + instance_url=server_url) -repo_push_template_html = Template(''' -User: ${data['actor']['username']}
-Branches: ${', '.join(branch['name'] for branch in data['push']['branches'])}
-Repository: ${data['repo']['url']}
-Commit: ${commit['raw_id']}
-URL: ${commit['url']}
-Author: ${commit['author']}
-Date: ${commit['date']}
-Commit Message:
-

${commit_msg}

-''') + email_body_html = repo_push_template_html.render( + 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)