[PATCH 6 of 6] email: move branch information close to repository in mail subjects

Thomas De Schampheleire patrickdepinguin at gmail.com
Tue Sep 1 16:28:38 UTC 2015


# HG changeset patch
# User Thomas De Schampheleire <thomas.de.schampheleire at gmail.com>
# Date 1436472369 -7200
#      Thu Jul 09 22:06:09 2015 +0200
# Node ID d695af497bb1b570aac5da7a64a024ae3c238f5a
# Parent  63dd90a5345e35b914a4f3842d4838e98fc7fdbc
email: move branch information close to repository in mail subjects

Move the branch information close to the repository in subjects of
comment/pullrequest mails, but hide the branch name if it is default (hg) or
master (git).

Add a Changeset method is_on_default_branch() to accomodate this without
needing to check the repo type in the email code.

Based on code by Cedric De Herdt.

diff --git a/kallithea/lib/vcs/backends/base.py b/kallithea/lib/vcs/backends/base.py
--- a/kallithea/lib/vcs/backends/base.py
+++ b/kallithea/lib/vcs/backends/base.py
@@ -671,6 +671,9 @@ class BaseChangeset(object):
     def obsolete(self):
         return False
 
+    def is_on_default_branch(self):
+        return self.branch == self.repository.DEFAULT_BRANCH_NAME
+
 class BaseWorkdir(object):
     """
     Working directory representation of single repository.
diff --git a/kallithea/model/comment.py b/kallithea/model/comment.py
--- a/kallithea/model/comment.py
+++ b/kallithea/model/comment.py
@@ -109,6 +109,7 @@ class ChangesetCommentsModel(BaseModel):
                 'repo_name': repo.repo_name,
                 'short_id': h.short_id(revision),
                 'branch': cs.branch,
+                'branch_ref': '#%s' % cs.branch if not cs.is_on_default_branch() else '',
                 'comment_username': user.username,
                 'threading': threading,
             }
@@ -116,7 +117,8 @@ class ChangesetCommentsModel(BaseModel):
         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(':')
+            _org_ref_type, org_ref_name, org_rev = comment.pull_request.org_ref.split(':')
+            org_cs = pull_request.org_repo.scm_instance.get_changeset(org_rev)
             threading = ['%s-pr-%s@%s' % (pull_request.other_repo.repo_name,
                                           pull_request.pull_request_id,
                                           h.canonical_hostname())]
@@ -154,7 +156,7 @@ class ChangesetCommentsModel(BaseModel):
                 'pr_target_repo': h.canonical_url('summary_home',
                                    repo_name=pull_request.other_repo.repo_name),
                 'repo_name': pull_request.other_repo.repo_name,
-                'ref': org_ref_name,
+                'branch_ref': '#%s' % org_ref_name if not org_cs.is_on_default_branch() else '',
                 'comment_username': user.username,
                 'threading': threading,
             }
diff --git a/kallithea/model/notification.py b/kallithea/model/notification.py
--- a/kallithea/model/notification.py
+++ b/kallithea/model/notification.py
@@ -299,13 +299,13 @@ class EmailNotificationModel(BaseModel):
             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_CHANGESET_COMMENT: _('[Comment] %(repo_name)s%(branch_ref)s changeset %(short_id)s: "%(message_short)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 %(ref)s'),
-            self.TYPE_PULL_REQUEST_COMMENT: _('[Comment] %(repo_name)s pull request %(pr_nice_id)s: "%(pr_title_short)s" from %(ref)s'),
+            self.TYPE_PULL_REQUEST: _('[Added] %(repo_name)s%(branch_ref)s pull request %(pr_nice_id)s: "%(pr_title_short)s"'),
+            self.TYPE_PULL_REQUEST_COMMENT: _('[Comment] %(repo_name)s%(branch_ref)s pull request %(pr_nice_id)s: "%(pr_title_short)s"'),
         }
 
     def get_email_description(self, type_, **kwargs):


More information about the kallithea-general mailing list