emails: added logic to allow overwriting the default email titles via rcextensions.

This commit is contained in:
Marcin Kuzminski 2020-07-16 12:37:52 +02:00
parent 50d91914f5
commit bdf49e02d6
6 changed files with 70 additions and 24 deletions

View file

@ -1,5 +1,6 @@
# This code allows override the integrations templates.
# Put this into the __init__.py file of rcextensions to override the templates
# Below code examples allows override the integrations templates, or email titles.
# Append selected parts at the end of the __init__.py file of rcextensions directory
# to override the templates
# EMAIL Integration
@ -185,3 +186,18 @@ ${commit['message']}
```
''')
# Example to modify emails default title
from rhodecode.model import notification
notification.EMAIL_PR_UPDATE_SUBJECT_TEMPLATE = '{updating_user} updated pull request. !{pr_id}: "{pr_title}"'
notification.EMAIL_PR_REVIEW_SUBJECT_TEMPLATE = '{user} requested a pull request review. !{pr_id}: "{pr_title}"'
notification.EMAIL_PR_COMMENT_SUBJECT_TEMPLATE = '{mention_prefix}{user} left a {comment_type} on pull request !{pr_id}: "{pr_title}"'
notification.EMAIL_PR_COMMENT_STATUS_CHANGE_SUBJECT_TEMPLATE = '{mention_prefix}[status: {status}] {user} left a {comment_type} on pull request !{pr_id}: "{pr_title}"'
notification.EMAIL_PR_COMMENT_FILE_SUBJECT_TEMPLATE = '{mention_prefix}{user} left a {comment_type} on file `{comment_file}` in pull request !{pr_id}: "{pr_title}"'
notification.EMAIL_COMMENT_SUBJECT_TEMPLATE = '{mention_prefix}{user} left a {comment_type} on commit `{commit_id}`'
notification.EMAIL_COMMENT_STATUS_CHANGE_SUBJECT_TEMPLATE = '{mention_prefix}[status: {status}] {user} left a {comment_type} on commit `{commit_id}`'
notification.EMAIL_COMMENT_FILE_SUBJECT_TEMPLATE = '{mention_prefix}{user} left a {comment_type} on file `{comment_file}` in commit `{commit_id}`'

View file

@ -295,6 +295,27 @@ class NotificationModel(BaseModel):
}
# Templates for Titles, that could be overwritten by rcextensions
# Title of email for pull-request update
EMAIL_PR_UPDATE_SUBJECT_TEMPLATE = ''
# Title of email for request for pull request review
EMAIL_PR_REVIEW_SUBJECT_TEMPLATE = ''
# Title of email for general comment on pull request
EMAIL_PR_COMMENT_SUBJECT_TEMPLATE = ''
# Title of email for general comment which includes status change on pull request
EMAIL_PR_COMMENT_STATUS_CHANGE_SUBJECT_TEMPLATE = ''
# Title of email for inline comment on a file in pull request
EMAIL_PR_COMMENT_FILE_SUBJECT_TEMPLATE = ''
# Title of email for general comment on commit
EMAIL_COMMENT_SUBJECT_TEMPLATE = ''
# Title of email for general comment which includes status change on commit
EMAIL_COMMENT_STATUS_CHANGE_SUBJECT_TEMPLATE = ''
# Title of email for inline comment on a file in commit
EMAIL_COMMENT_FILE_SUBJECT_TEMPLATE = ''
class EmailNotificationModel(BaseModel):
TYPE_COMMIT_COMMENT = Notification.TYPE_CHANGESET_COMMENT
TYPE_REGISTRATION = Notification.TYPE_REGISTRATION

View file

@ -17,19 +17,22 @@ data = {
'commit_id': h.show_id(commit),
'mention_prefix': '[mention] ' if mention else '',
}
if comment_file:
subject_template = email_comment_file_subject_template or \
_('{mention_prefix}{user} left a {comment_type} on file `{comment_file}` in commit `{commit_id}` in the `{repo_name}` repository').format(**data)
else:
if status_change:
subject_template = email_comment_status_change_subject_template or \
_('{mention_prefix}[status: {status}] {user} left a {comment_type} on commit `{commit_id}` in the `{repo_name}` repository').format(**data)
else:
subject_template = email_comment_subject_template or \
_('{mention_prefix}{user} left a {comment_type} on commit `{commit_id}` in the `{repo_name}` repository').format(**data)
%>
% if comment_file:
${_('{mention_prefix}{user} left a {comment_type} on file `{comment_file}` in commit `{commit_id}`').format(**data)} ${_('in the `{repo_name}` repository').format(**data) |n}
% else:
% if status_change:
${_('{mention_prefix}[status: {status}] {user} left a {comment_type} on commit `{commit_id}`').format(**data) |n} ${_('in the `{repo_name}` repository').format(**data) |n}
% else:
${_('{mention_prefix}{user} left a {comment_type} on commit `{commit_id}`').format(**data) |n} ${_('in the `{repo_name}` repository').format(**data) |n}
% endif
% endif
${subject_template.format(**data) |n}
</%def>
## PLAINTEXT VERSION OF BODY

View file

@ -18,19 +18,21 @@ data = {
'pr_id': pull_request.pull_request_id,
'mention_prefix': '[mention] ' if mention else '',
}
if comment_file:
subject_template = email_pr_comment_file_subject_template or \
_('{mention_prefix}{user} left a {comment_type} on file `{comment_file}` in pull request !{pr_id}: "{pr_title}"').format(**data)
else:
if status_change:
subject_template = email_pr_comment_status_change_subject_template or \
_('{mention_prefix}[status: {status}] {user} left a {comment_type} on pull request !{pr_id}: "{pr_title}"').format(**data)
else:
subject_template = email_pr_comment_subject_template or \
_('{mention_prefix}{user} left a {comment_type} on pull request !{pr_id}: "{pr_title}"').format(**data)
%>
% if comment_file:
${_('{mention_prefix}{user} left a {comment_type} on file `{comment_file}` in pull request !{pr_id}: "{pr_title}"').format(**data) |n}
% else:
% if status_change:
${_('{mention_prefix}[status: {status}] {user} left a {comment_type} on pull request !{pr_id}: "{pr_title}"').format(**data) |n}
% else:
${_('{mention_prefix}{user} left a {comment_type} on pull request !{pr_id}: "{pr_title}"').format(**data) |n}
% endif
% endif
${subject_template.format(**data) |n}
</%def>
## PLAINTEXT VERSION OF BODY

View file

@ -10,9 +10,11 @@ data = {
'pr_id': pull_request.pull_request_id,
'pr_title': pull_request.title,
}
subject_template = email_pr_review_subject_template or _('{user} requested a pull request review. !{pr_id}: "{pr_title}"')
%>
${_('{user} requested a pull request review. !{pr_id}: "{pr_title}"').format(**data) |n}
${subject_template.format(**data) |n}
</%def>
## PLAINTEXT VERSION OF BODY

View file

@ -10,9 +10,11 @@ data = {
'pr_id': pull_request.pull_request_id,
'pr_title': pull_request.title,
}
subject_template = email_pr_update_subject_template or _('{updating_user} updated pull request. !{pr_id}: "{pr_title}"')
%>
${_('{updating_user} updated pull request. !{pr_id}: "{pr_title}"').format(**data) |n}
${subject_template.format(**data) |n}
</%def>
## PLAINTEXT VERSION OF BODY