Mercurial > kallithea
changeset 6056:3a221939a19f
notifications: make more template strings available for mails
To be used soon ...
author | Mads Kiilerich <madski@unity3d.com> |
---|---|
date | Thu, 28 Jul 2016 16:30:28 +0200 |
parents | cd32d44ee7ff |
children | 552800808386 |
files | kallithea/lib/helpers.py kallithea/model/comment.py kallithea/model/notification.py kallithea/model/pull_request.py kallithea/tests/models/test_notifications.py |
diffstat | 5 files changed, 74 insertions(+), 12 deletions(-) [+] |
line wrap: on
line diff
--- a/kallithea/lib/helpers.py Thu Jul 28 16:28:34 2016 +0200 +++ b/kallithea/lib/helpers.py Thu Jul 28 16:30:28 2016 +0200 @@ -101,8 +101,12 @@ .replace("'", "'") ) -def shorter(s, size=20): - postfix = '...' +def shorter(s, size=20, firstline=False, postfix='...'): + """Truncate s to size, including the postfix string if truncating. + If firstline, truncate at newline. + """ + if firstline: + s = s.split('\n', 1)[0].rstrip() if len(s) > size: return s[:size - len(postfix)] + postfix return s
--- a/kallithea/model/comment.py Thu Jul 28 16:28:34 2016 +0200 +++ b/kallithea/model/comment.py Thu Jul 28 16:30:28 2016 +0200 @@ -88,6 +88,7 @@ cs_author = User.get_from_cs_author(cs.author) if not cs_author: #use repo owner if we cannot extract the author correctly + # FIXME: just use committer name even if not a user cs_author = repo.user recipients += [cs_author] email_kwargs = { @@ -97,6 +98,7 @@ 'cs_comment_url': comment_url, 'raw_id': revision, 'message': cs.message, + 'cs_author': cs_author, 'repo_name': repo.repo_name, 'short_id': h.short_id(revision), 'branch': cs.branch, @@ -108,6 +110,7 @@ notification_type = Notification.TYPE_PULL_REQUEST_COMMENT desc = comment.pull_request.title _org_ref_type, org_ref_name, _org_rev = comment.pull_request.org_ref.split(':') + _other_ref_type, other_ref_name, _other_rev = comment.pull_request.other_ref.split(':') threading = ['%s-pr-%s@%s' % (pull_request.other_repo.repo_name, pull_request.pull_request_id, h.canonical_hostname())] @@ -143,8 +146,12 @@ 'pr_comment_user': user.full_name_and_username, 'pr_target_repo': h.canonical_url('summary_home', repo_name=pull_request.other_repo.repo_name), + 'pr_target_branch': other_ref_name, + 'pr_source_repo': h.canonical_url('summary_home', + repo_name=pull_request.org_repo.repo_name), + 'pr_source_branch': org_ref_name, + 'pr_owner': pull_request.owner, 'repo_name': pull_request.other_repo.repo_name, - 'ref': org_ref_name, 'comment_username': user.username, 'threading': threading, }
--- a/kallithea/model/notification.py Thu Jul 28 16:28:34 2016 +0200 +++ b/kallithea/model/notification.py Thu Jul 28 16:30:28 2016 +0200 @@ -304,8 +304,8 @@ # self.TYPE_PASSWORD_RESET self.TYPE_REGISTRATION: _('New user %(new_username)s registered'), # self.TYPE_DEFAULT - self.TYPE_PULL_REQUEST: _('[Added] %(repo_name)s pull request %(pr_nice_id)s from %(ref)s'), - self.TYPE_PULL_REQUEST_COMMENT: _('[Comment] %(repo_name)s pull request %(pr_nice_id)s from %(ref)s'), + self.TYPE_PULL_REQUEST: _('[Added] %(repo_name)s pull request %(pr_nice_id)s from %(pr_source_branch)s'), + self.TYPE_PULL_REQUEST_COMMENT: _('[Comment] %(repo_name)s pull request %(pr_nice_id)s from %(pr_source_branch)s'), } def get_email_description(self, type_, **kwargs):
--- a/kallithea/model/pull_request.py Thu Jul 28 16:28:34 2016 +0200 +++ b/kallithea/model/pull_request.py Thu Jul 28 16:30:28 2016 +0200 @@ -153,6 +153,7 @@ ) body = pr.description _org_ref_type, org_ref_name, _org_rev = pr.org_ref.split(':') + _other_ref_type, other_ref_name, _other_rev = pr.other_ref.split(':') email_kwargs = { 'pr_title': pr.title, 'pr_user_created': user.full_name_and_username, @@ -162,7 +163,13 @@ 'repo_name': pr.other_repo.repo_name, 'org_repo_name': pr.org_repo.repo_name, 'pr_nice_id': pr.nice_id(), - 'ref': org_ref_name, + 'pr_target_repo': h.canonical_url('summary_home', + repo_name=pr.other_repo.repo_name), + 'pr_target_branch': other_ref_name, + 'pr_source_repo': h.canonical_url('summary_home', + repo_name=pr.org_repo.repo_name), + 'pr_source_branch': org_ref_name, + 'pr_owner': pr.owner, 'pr_username': user.username, 'threading': threading, 'is_mention': False,
--- a/kallithea/tests/models/test_notifications.py Thu Jul 28 16:28:34 2016 +0200 +++ b/kallithea/tests/models/test_notifications.py Thu Jul 28 16:30:28 2016 +0200 @@ -182,15 +182,59 @@ l.append('<html><body>\n') with mock.patch.object(kallithea.lib.celerylib.tasks, 'send_email', send_email): - pr_kwargs = dict(pr_nice_id='#7', ref='devbranch', org_repo_name='repo_org', pr_title='The Title', pr_url='http://pr.org/7') + pr_kwargs = dict( + pr_nice_id='#7', + pr_title='The Title', + pr_url='http://pr.org/7', + pr_target_repo='http://mainline.com/repo', + pr_target_branch='trunk', + pr_source_repo='https://dev.org/repo', + pr_source_branch='devbranch', + pr_owner=User.get(self.u2), + ) for type_, body, kwargs in [ - (Notification.TYPE_CHANGESET_COMMENT, u'This is the new comment.\n\n - and here it ends indented.', dict(short_id='cafe1234', raw_id='cafe1234c0ffeecafe', branch='brunch', cs_comment_user='Opinionated User (jsmith)', cs_comment_url='http://comment.org', is_mention=[False, True], message='This changeset did something clever which is hard to explain', status_change=[None, 'Approved'], cs_target_repo='repo_target', cs_url='http://changeset.com')), - (Notification.TYPE_MESSAGE, u'This is the body of the test message\n - nothing interesting here except indentation.', dict()), + (Notification.TYPE_CHANGESET_COMMENT, + u'This is the new comment.\n\n - and here it ends indented.', + dict( + short_id='cafe1234', + raw_id='cafe1234c0ffeecafe', + branch='brunch', + cs_comment_user='Opinionated User (jsmith)', + cs_comment_url='http://comment.org', + is_mention=[False, True], + message='This changeset did something clever which is hard to explain', + status_change=[None, 'Approved'], + cs_target_repo='repo_target', + cs_url='http://changeset.com', + cs_author=User.get(self.u2))), + (Notification.TYPE_MESSAGE, + u'This is the body of the test message\n - nothing interesting here except indentation.', + dict()), #(Notification.TYPE_MENTION, '$body', None), # not used - (Notification.TYPE_REGISTRATION, u'Registration body', dict(new_username='newbie', registered_user_url='http://newbie.org', new_email='new@email.com', new_full_name='New Full Name')), - (Notification.TYPE_PULL_REQUEST, u'This PR is awesome because it does stuff\n - please approve indented!', dict(pr_user_created='Requesting User (root)', is_mention=[False, True], pr_revisions=[('123abc'*7, "Introduce one and two\n\nand that's it"), ('567fed'*7, 'Make one plus two equal tree')], **pr_kwargs)), - (Notification.TYPE_PULL_REQUEST_COMMENT, u'Me too!\n\n - and indented on second line', dict(closing_pr=[False, True], pr_comment_user='Opinionated User (jsmith)', pr_comment_url='http://pr.org/comment', status_change=[None, 'Under Review'], pr_target_repo='http://target.com/repo', **pr_kwargs)), + (Notification.TYPE_REGISTRATION, + u'Registration body', + dict( + new_username='newbie', + registered_user_url='http://newbie.org', + new_email='new@email.com', + new_full_name='New Full Name')), + (Notification.TYPE_PULL_REQUEST, + u'This PR is awesome because it does stuff\n - please approve indented!', + dict( + pr_user_created='Requesting User (root)', # pr_owner should perhaps be used for @mention in description ... + is_mention=[False, True], + pr_revisions=[('123abc'*7, "Introduce one and two\n\nand that's it"), ('567fed'*7, 'Make one plus two equal tree')], + org_repo_name='repo_org', + **pr_kwargs)), + (Notification.TYPE_PULL_REQUEST_COMMENT, + u'Me too!\n\n - and indented on second line', + dict( + closing_pr=[False, True], + pr_comment_user='Opinionated User (jsmith)', + pr_comment_url='http://pr.org/comment', + status_change=[None, 'Under Review'], + **pr_kwargs)), ]: kwargs['repo_name'] = u'repo/name' params = [(type_, type_, body, kwargs)]