[PATCH 5 of 5] e-mail: move branch information close to repository in mail subjects

Thomas De Schampheleire patrickdepinguin at gmail.com
Mon Jul 13 04:45:11 EDT 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 fb662c5f01053122694080716216a6985c8b54f6
# Parent  46d77b6a81fb27aa9b7f247fed5138f1125ec019
e-mail: 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 e-mail 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
@@ -667,6 +667,9 @@ class BaseChangeset(object):
     def closesbranch(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