Changeset - bd5d70b6f445
[Not reviewed]
default
0 5 0
Thomas De Schampheleire <thomas.de.schampheleire at gmail.com> - 10 years ago 2015-07-09 22:17:26

email: add relevant title to subject of emails

For comment and pullrequest mails, add changeset/pullrequest title (shortened
to first 50 characters of first line)
5 files changed with 22 insertions and 17 deletions:
0 comments (0 inline, 0 general)
kallithea/model/comment.py
Show inline comments
 
@@ -89,24 +89,25 @@ class ChangesetCommentsModel(BaseModel):
 
            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 = {
 
                'status_change': status_change,
 
                'cs_comment_user': user.full_name_and_username,
 
                'cs_target_repo': h.canonical_url('summary_home', repo_name=repo.repo_name),
 
                'cs_comment_url': comment_url,
 
                'raw_id': revision,
 
                'message': cs.message,
 
                'message_short': h.shorter(cs.message, 50, firstline=True),
 
                'cs_author': cs_author,
 
                'repo_name': repo.repo_name,
 
                'short_id': h.short_id(revision),
 
                'branch': cs.branch,
 
                'comment_username': user.username,
 
                'threading': threading,
 
            }
 
        #pull request
 
        elif pull_request:
 
            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(':')
 
@@ -130,24 +131,25 @@ class ChangesetCommentsModel(BaseModel):
 
            # get the current participants of this pull request
 
            recipients = ChangesetComment.get_users(pull_request_id=
 
                                                pull_request.pull_request_id)
 
            # add pull request author
 
            recipients += [pull_request.owner]
 

	
 
            # add the reviewers to notification
 
            recipients += pull_request.get_reviewer_users()
 

	
 
            #set some variables for email notification
 
            email_kwargs = {
 
                'pr_title': pull_request.title,
 
                'pr_title_short': h.shorter(pull_request.title, 50),
 
                'pr_nice_id': pull_request.nice_id(),
 
                'status_change': status_change,
 
                'closing_pr': closing_pr,
 
                'pr_comment_url': comment_url,
 
                '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,
kallithea/model/notification.py
Show inline comments
 
@@ -290,31 +290,31 @@ class EmailNotificationModel(BaseModel):
 
        super(EmailNotificationModel, self).__init__()
 
        self._template_root = kallithea.CONFIG['pylons.paths']['templates'][0]
 
        self._tmpl_lookup = kallithea.CONFIG['pylons.app_globals'].mako_lookup
 
        self.email_types = {
 
            self.TYPE_CHANGESET_COMMENT: 'changeset_comment',
 
            self.TYPE_PASSWORD_RESET: 'password_reset',
 
            self.TYPE_REGISTRATION: 'registration',
 
            self.TYPE_DEFAULT: 'default',
 
            self.TYPE_PULL_REQUEST: 'pull_request',
 
            self.TYPE_PULL_REQUEST_COMMENT: 'pull_request_comment',
 
        }
 
        self._subj_map = {
 
            self.TYPE_CHANGESET_COMMENT: _('[Comment] %(repo_name)s changeset %(short_id)s on %(branch)s'),
 
            self.TYPE_CHANGESET_COMMENT: _('[Comment] %(repo_name)s changeset %(short_id)s "%(message_short)s" on %(branch)s'),
 
            self.TYPE_MESSAGE: 'Test Message',
 
            # 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 %(pr_source_branch)s'),
 
            self.TYPE_PULL_REQUEST_COMMENT: _('[Comment] %(repo_name)s pull request %(pr_nice_id)s from %(pr_source_branch)s'),
 
            self.TYPE_PULL_REQUEST: _('[Added] %(repo_name)s pull request %(pr_nice_id)s "%(pr_title_short)s" from %(pr_source_branch)s'),
 
            self.TYPE_PULL_REQUEST_COMMENT: _('[Comment] %(repo_name)s pull request %(pr_nice_id)s "%(pr_title_short)s" from %(pr_source_branch)s'),
 
        }
 

	
 
    def get_email_description(self, type_, **kwargs):
 
        """
 
        return subject for email based on given type
 
        """
 
        tmpl = self._subj_map[type_]
 
        try:
 
            subj = tmpl % kwargs
 
        except KeyError as e:
 
            log.error('error generating email subject for %r from %s: %s', type_, ','.join(self._subj_map.keys()), e)
 
            raise
kallithea/model/pull_request.py
Show inline comments
 
@@ -147,24 +147,25 @@ class PullRequestModel(BaseModel):
 
            h.link_to(
 
              _('%(user)s wants you to review pull request %(pr_nice_id)s: %(pr_title)s') % \
 
                {'user': user.username,
 
                 'pr_title': pr.title,
 
                 'pr_nice_id': pr.nice_id()},
 
                pr_url)
 
            )
 
        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_title_short': h.shorter(pr.title, 50),
 
            'pr_user_created': user.full_name_and_username,
 
            'pr_repo_url': h.canonical_url('summary_home', repo_name=pr.other_repo.repo_name),
 
            'pr_url': pr_url,
 
            'pr_revisions': revision_data,
 
            'repo_name': pr.other_repo.repo_name,
 
            'org_repo_name': pr.org_repo.repo_name,
 
            'pr_nice_id': pr.nice_id(),
 
            '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),
kallithea/tests/models/test_dump_html_mails.ref.html
Show inline comments
 
<html><body>
 

	
 

	
 
<h1>cs_comment, is_mention=False, status_change=None</h1>
 
<pre>
 

	
 
From: u1
 
To: u2@example.com
 
Subject: [Comment] repo/name changeset cafe1234 on brunch
 
Subject: [Comment] repo/name changeset cafe1234 "This changeset did something cl..." on brunch
 

	
 
--------------------
 

	
 

	
 
Comment from Opinionated User (jsmith) on repo_target changeset cafe1234c0ff:
 
This is the new comment.
 

	
 
 - and here it ends indented.
 

	
 

	
 
URL: http://comment.org
 

	
 
@@ -49,25 +49,25 @@ This changeset did something clever whic
 
<br/>
 
-- <br/>
 
This is an automatic notification. Don&#39;t reply to this mail.
 

	
 
<pre>--------------------</pre>
 

	
 

	
 
<h1>cs_comment, is_mention=True, status_change=None</h1>
 
<pre>
 

	
 
From: u1
 
To: u2@example.com
 
Subject: [Comment] repo/name changeset cafe1234 on brunch
 
Subject: [Comment] repo/name changeset cafe1234 "This changeset did something cl..." on brunch
 

	
 
--------------------
 

	
 

	
 
Comment from Opinionated User (jsmith) on repo_target changeset cafe1234c0ff mentioned you:
 
This is the new comment.
 

	
 
 - and here it ends indented.
 

	
 

	
 
URL: http://comment.org
 

	
 
@@ -101,25 +101,25 @@ This changeset did something clever whic
 
<br/>
 
-- <br/>
 
This is an automatic notification. Don&#39;t reply to this mail.
 

	
 
<pre>--------------------</pre>
 

	
 

	
 
<h1>cs_comment, is_mention=False, status_change='Approved'</h1>
 
<pre>
 

	
 
From: u1
 
To: u2@example.com
 
Subject: [Approved: Comment] repo/name changeset cafe1234 on brunch
 
Subject: [Approved: Comment] repo/name changeset cafe1234 "This changeset did something cl..." on brunch
 

	
 
--------------------
 

	
 

	
 
Comment from Opinionated User (jsmith) on repo_target changeset cafe1234c0ff:
 
This is the new comment.
 

	
 
 - and here it ends indented.
 

	
 
The changeset status was changed to: Approved
 

	
 
URL: http://comment.org
 
@@ -155,25 +155,25 @@ This changeset did something clever whic
 
<br/>
 
-- <br/>
 
This is an automatic notification. Don&#39;t reply to this mail.
 

	
 
<pre>--------------------</pre>
 

	
 

	
 
<h1>cs_comment, is_mention=True, status_change='Approved'</h1>
 
<pre>
 

	
 
From: u1
 
To: u2@example.com
 
Subject: [Approved: Comment] repo/name changeset cafe1234 on brunch
 
Subject: [Approved: Comment] repo/name changeset cafe1234 "This changeset did something cl..." on brunch
 

	
 
--------------------
 

	
 

	
 
Comment from Opinionated User (jsmith) on repo_target changeset cafe1234c0ff mentioned you:
 
This is the new comment.
 

	
 
 - and here it ends indented.
 

	
 
The changeset status was changed to: Approved
 

	
 
URL: http://comment.org
 
@@ -277,25 +277,25 @@ View this user here: <a href="http://new
 
<br/>
 
-- <br/>
 
This is an automatic notification. Don&#39;t reply to this mail.
 

	
 
<pre>--------------------</pre>
 

	
 

	
 
<h1>pull_request, is_mention=False</h1>
 
<pre>
 

	
 
From: u1
 
To: u2@example.com
 
Subject: [Added] repo/name pull request #7 from devbranch
 
Subject: [Added] repo/name pull request #7 "The Title" from devbranch
 

	
 
--------------------
 

	
 

	
 
Requesting User (root) requested your review of repo/name pull request "The Title"
 

	
 
URL: http://pr.org/7
 

	
 
Description:
 
This PR is awesome because it does stuff
 
 - please approve indented!
 

	
 
@@ -342,25 +342,25 @@ Make one plus two equal tree
 
<br/>
 
-- <br/>
 
This is an automatic notification. Don&#39;t reply to this mail.
 

	
 
<pre>--------------------</pre>
 

	
 

	
 
<h1>pull_request, is_mention=True</h1>
 
<pre>
 

	
 
From: u1
 
To: u2@example.com
 
Subject: [Added] repo/name pull request #7 from devbranch
 
Subject: [Added] repo/name pull request #7 "The Title" from devbranch
 

	
 
--------------------
 

	
 

	
 
Requesting User (root) mentioned you on repo/name pull request "The Title"
 

	
 
URL: http://pr.org/7
 

	
 
Description:
 
This PR is awesome because it does stuff
 
 - please approve indented!
 

	
 
@@ -407,25 +407,25 @@ Make one plus two equal tree
 
<br/>
 
-- <br/>
 
This is an automatic notification. Don&#39;t reply to this mail.
 

	
 
<pre>--------------------</pre>
 

	
 

	
 
<h1>pull_request_comment, is_mention=False, status_change=None, closing_pr=False</h1>
 
<pre>
 

	
 
From: u1
 
To: u2@example.com
 
Subject: [Comment] repo/name pull request #7 from devbranch
 
Subject: [Comment] repo/name pull request #7 "The Title" from devbranch
 

	
 
--------------------
 

	
 

	
 
Comment from Opinionated User (jsmith) on repo/name pull request "The Title":
 
Me too!
 

	
 
 - and indented on second line
 

	
 

	
 
URL: http://pr.org/comment
 

	
 
@@ -450,25 +450,25 @@ This is an automatic notification. Don't
 
<br/>
 
-- <br/>
 
This is an automatic notification. Don&#39;t reply to this mail.
 

	
 
<pre>--------------------</pre>
 

	
 

	
 
<h1>pull_request_comment, is_mention=True, status_change=None, closing_pr=False</h1>
 
<pre>
 

	
 
From: u1
 
To: u2@example.com
 
Subject: [Comment] repo/name pull request #7 from devbranch
 
Subject: [Comment] repo/name pull request #7 "The Title" from devbranch
 

	
 
--------------------
 

	
 

	
 
Comment from Opinionated User (jsmith) on repo/name pull request "The Title":
 
Me too!
 

	
 
 - and indented on second line
 

	
 

	
 
URL: http://pr.org/comment
 

	
 
@@ -493,25 +493,25 @@ This is an automatic notification. Don't
 
<br/>
 
-- <br/>
 
This is an automatic notification. Don&#39;t reply to this mail.
 

	
 
<pre>--------------------</pre>
 

	
 

	
 
<h1>pull_request_comment, is_mention=False, status_change='Under Review', closing_pr=False</h1>
 
<pre>
 

	
 
From: u1
 
To: u2@example.com
 
Subject: [Under Review: Comment] repo/name pull request #7 from devbranch
 
Subject: [Under Review: Comment] repo/name pull request #7 "The Title" from devbranch
 

	
 
--------------------
 

	
 

	
 
Comment from Opinionated User (jsmith) on repo/name pull request "The Title":
 
Me too!
 

	
 
 - and indented on second line
 

	
 
The comment was made with status: Under Review
 

	
 
URL: http://pr.org/comment
 
@@ -538,25 +538,25 @@ This is an automatic notification. Don't
 
<br/>
 
-- <br/>
 
This is an automatic notification. Don&#39;t reply to this mail.
 

	
 
<pre>--------------------</pre>
 

	
 

	
 
<h1>pull_request_comment, is_mention=True, status_change='Under Review', closing_pr=False</h1>
 
<pre>
 

	
 
From: u1
 
To: u2@example.com
 
Subject: [Under Review: Comment] repo/name pull request #7 from devbranch
 
Subject: [Under Review: Comment] repo/name pull request #7 "The Title" from devbranch
 

	
 
--------------------
 

	
 

	
 
Comment from Opinionated User (jsmith) on repo/name pull request "The Title":
 
Me too!
 

	
 
 - and indented on second line
 

	
 
The comment was made with status: Under Review
 

	
 
URL: http://pr.org/comment
 
@@ -583,25 +583,25 @@ This is an automatic notification. Don't
 
<br/>
 
-- <br/>
 
This is an automatic notification. Don&#39;t reply to this mail.
 

	
 
<pre>--------------------</pre>
 

	
 

	
 
<h1>pull_request_comment, is_mention=False, status_change=None, closing_pr=True</h1>
 
<pre>
 

	
 
From: u1
 
To: u2@example.com
 
Subject: [Closing: Comment] repo/name pull request #7 from devbranch
 
Subject: [Closing: Comment] repo/name pull request #7 "The Title" from devbranch
 

	
 
--------------------
 

	
 

	
 
Comment from Opinionated User (jsmith) on repo/name pull request "The Title":
 
Me too!
 

	
 
 - and indented on second line
 

	
 

	
 
URL: http://pr.org/comment
 

	
 
@@ -626,25 +626,25 @@ This is an automatic notification. Don't
 
<br/>
 
-- <br/>
 
This is an automatic notification. Don&#39;t reply to this mail.
 

	
 
<pre>--------------------</pre>
 

	
 

	
 
<h1>pull_request_comment, is_mention=True, status_change=None, closing_pr=True</h1>
 
<pre>
 

	
 
From: u1
 
To: u2@example.com
 
Subject: [Closing: Comment] repo/name pull request #7 from devbranch
 
Subject: [Closing: Comment] repo/name pull request #7 "The Title" from devbranch
 

	
 
--------------------
 

	
 

	
 
Comment from Opinionated User (jsmith) on repo/name pull request "The Title":
 
Me too!
 

	
 
 - and indented on second line
 

	
 

	
 
URL: http://pr.org/comment
 

	
 
@@ -669,25 +669,25 @@ This is an automatic notification. Don't
 
<br/>
 
-- <br/>
 
This is an automatic notification. Don&#39;t reply to this mail.
 

	
 
<pre>--------------------</pre>
 

	
 

	
 
<h1>pull_request_comment, is_mention=False, status_change='Under Review', closing_pr=True</h1>
 
<pre>
 

	
 
From: u1
 
To: u2@example.com
 
Subject: [Under Review, Closing: Comment] repo/name pull request #7 from devbranch
 
Subject: [Under Review, Closing: Comment] repo/name pull request #7 "The Title" from devbranch
 

	
 
--------------------
 

	
 

	
 
Comment from Opinionated User (jsmith) on repo/name pull request "The Title":
 
Me too!
 

	
 
 - and indented on second line
 

	
 
The comment closed the pull request with status: Under Review
 

	
 
URL: http://pr.org/comment
 
@@ -714,25 +714,25 @@ This is an automatic notification. Don't
 
<br/>
 
-- <br/>
 
This is an automatic notification. Don&#39;t reply to this mail.
 

	
 
<pre>--------------------</pre>
 

	
 

	
 
<h1>pull_request_comment, is_mention=True, status_change='Under Review', closing_pr=True</h1>
 
<pre>
 

	
 
From: u1
 
To: u2@example.com
 
Subject: [Under Review, Closing: Comment] repo/name pull request #7 from devbranch
 
Subject: [Under Review, Closing: Comment] repo/name pull request #7 "The Title" from devbranch
 

	
 
--------------------
 

	
 

	
 
Comment from Opinionated User (jsmith) on repo/name pull request "The Title":
 
Me too!
 

	
 
 - and indented on second line
 

	
 
The comment closed the pull request with status: Under Review
 

	
 
URL: http://pr.org/comment
kallithea/tests/models/test_notifications.py
Show inline comments
 
@@ -176,43 +176,45 @@ class TestNotifications(TestController):
 
            l.append('To: %s\n' % ' '.join(recipients))
 
            l.append('Subject: %s\n' % subject)
 
            l.append('\n--------------------\n%s\n--------------------' % body)
 
            l.append('</pre>\n')
 
            l.append('\n%s\n' % html_body)
 
            l.append('<pre>--------------------</pre>\n')
 

	
 
        l.append('<html><body>\n')
 
        with mock.patch.object(kallithea.lib.celerylib.tasks, 'send_email', send_email):
 
            pr_kwargs = dict(
 
                pr_nice_id='#7',
 
                pr_title='The Title',
 
                pr_title_short='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',
 
                    message_short='This changeset did something cl...',
 
                    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',
0 comments (0 inline, 0 general)