Changeset - d4061c6cc0e2
[Not reviewed]
default
0 5 0
Mads Kiilerich - 9 years ago 2016-07-28 16:34:29
madski@unity3d.com
notifications: tweak PR mail subject lines

The subject line is used for mail threading in gmail and can thus not be
changed without impacting users ... but now we do it.

* The tag '[Review]' is more spot-on than '[Added]'.
* The subject should be short so it fits on one line, so abbreviate "pull
request" to PR.
* Add the PR owner - convenient for filtering comments on own PRs from comments
on other PRs.
5 files changed with 15 insertions and 12 deletions:
0 comments (0 inline, 0 general)
kallithea/model/comment.py
Show inline comments
 
@@ -144,24 +144,25 @@ class ChangesetCommentsModel(BaseModel):
 
                '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,
 
                'pr_owner_username': pull_request.owner.username,
 
                'repo_name': pull_request.other_repo.repo_name,
 
                'comment_username': user.username,
 
                'threading': threading,
 
            }
 

	
 
        return subj, body, recipients, notification_type, email_kwargs
 

	
 
    def create(self, text, repo, user, revision=None, pull_request=None,
 
               f_path=None, line_no=None, status_change=None, closing_pr=False,
 
               send_email=True):
 
        """
 
        Creates a new comment for either a changeset or a pull request.
kallithea/model/notification.py
Show inline comments
 
@@ -295,26 +295,26 @@ class EmailNotificationModel(BaseModel):
 
            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 "%(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 "%(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'),
 
            self.TYPE_PULL_REQUEST: _('[Review] %(repo_name)s PR %(pr_nice_id)s "%(pr_title_short)s" from %(pr_source_branch)s by %(pr_owner_username)s'),
 
            self.TYPE_PULL_REQUEST_COMMENT: _('[Comment] %(repo_name)s PR %(pr_nice_id)s "%(pr_title_short)s" from %(pr_source_branch)s by %(pr_owner_username)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
 
@@ -162,24 +162,25 @@ class PullRequestModel(BaseModel):
 
            '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),
 
            'pr_source_branch': org_ref_name,
 
            'pr_owner': pr.owner,
 
            'pr_owner_username': pr.owner.username,
 
            'pr_username': user.username,
 
            'threading': threading,
 
            'is_mention': False,
 
            }
 
        if reviewers:
 
            NotificationModel().create(created_by=user, subject=subject, body=body,
 
                                       recipients=reviewers,
 
                                       type_=Notification.TYPE_PULL_REQUEST,
 
                                       email_kwargs=email_kwargs)
 

	
 
        if mention_recipients:
 
            mention_recipients.difference_update(reviewers)
kallithea/tests/models/test_dump_html_mails.ref.html
Show inline comments
 
@@ -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 "The Title" from devbranch
 
Subject: [Review] repo/name PR #7 "The Title" from devbranch by u2
 

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

	
 

	
 
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 "The Title" from devbranch
 
Subject: [Review] repo/name PR #7 "The Title" from devbranch by u2
 

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

	
 

	
 
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 "The Title" from devbranch
 
Subject: [Comment] repo/name PR #7 "The Title" from devbranch by u2
 

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

	
 

	
 
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 "The Title" from devbranch
 
Subject: [Comment] repo/name PR #7 "The Title" from devbranch by u2
 

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

	
 

	
 
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 "The Title" from devbranch
 
Subject: [Under Review: Comment] repo/name PR #7 "The Title" from devbranch by u2
 

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

	
 

	
 
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 "The Title" from devbranch
 
Subject: [Under Review: Comment] repo/name PR #7 "The Title" from devbranch by u2
 

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

	
 

	
 
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 "The Title" from devbranch
 
Subject: [Closing: Comment] repo/name PR #7 "The Title" from devbranch by u2
 

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

	
 

	
 
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 "The Title" from devbranch
 
Subject: [Closing: Comment] repo/name PR #7 "The Title" from devbranch by u2
 

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

	
 

	
 
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 "The Title" from devbranch
 
Subject: [Under Review, Closing: Comment] repo/name PR #7 "The Title" from devbranch by u2
 

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

	
 

	
 
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 "The Title" from devbranch
 
Subject: [Under Review, Closing: Comment] repo/name PR #7 "The Title" from devbranch by u2
 

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

	
 

	
 
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
 
@@ -183,24 +183,25 @@ class TestNotifications(TestController):
 
        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),
 
                pr_owner_username='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],
0 comments (0 inline, 0 general)