changeset 4446:5e7c69707f08

notifications: fix threading - use line number TODO: Use a more stable link, something that includes the filename.
author Mads Kiilerich <madski@unity3d.com>
date Tue, 12 Aug 2014 13:08:23 +0200
parents f9bc28c44f30
children e30401bac6e1
files kallithea/lib/helpers.py kallithea/model/comment.py kallithea/model/pull_request.py
diffstat 3 files changed, 26 insertions(+), 9 deletions(-) [+]
line wrap: on
line diff
--- a/kallithea/lib/helpers.py	Tue Aug 12 13:08:23 2014 +0200
+++ b/kallithea/lib/helpers.py	Tue Aug 12 13:08:23 2014 +0200
@@ -79,6 +79,16 @@
         kargs['qualified'] = True
     return url(*args, **kargs)
 
+def canonical_hostname():
+    '''Return canonical hostname of system'''
+    from kallithea import CONFIG
+    try:
+        parts = CONFIG.get('canonical_url', '').split('://', 1)
+        return parts[1].split('/', 1)[0]
+    except IndexError:
+        parts = url('home', qualified=True).split('://', 1)
+        return parts[1].split('/', 1)[0]
+
 def html_escape(text, html_escape_table=None):
     """Produce entities within text."""
     if not html_escape_table:
--- a/kallithea/model/comment.py	Tue Aug 12 13:08:23 2014 +0200
+++ b/kallithea/model/comment.py	Tue Aug 12 13:08:23 2014 +0200
@@ -81,9 +81,10 @@
             cs = repo.scm_instance.get_changeset(revision)
             desc = "%s" % (cs.short_id)
 
-            revision_url = h.canonical_url('changeset_home',
-                repo_name=repo.repo_name,
-                revision=revision)
+            threading = ['%s-rev-%s@%s' % (repo.repo_name, revision, h.canonical_hostname())]
+            if line_no: # TODO: url to file _and_ line number
+                threading.append('%s-rev-%s-line-%s@%s' % (repo.repo_name, revision, line_no,
+                                                           h.canonical_hostname()))
             comment_url = h.canonical_url('changeset_home',
                 repo_name=repo.repo_name,
                 revision=revision,
@@ -112,16 +113,20 @@
                 'short_id': h.short_id(revision),
                 'branch': cs.branch,
                 'comment_username': user.username,
-                'threading': [revision_url, comment_url], # TODO: url to line number
+                '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(':')
-            pr_url = h.canonical_url('pullrequest_show',
-                repo_name=pull_request.other_repo.repo_name,
-                pull_request_id=pull_request.pull_request_id)
+            threading = ['%s-pr-%s@%s' % (pull_request.other_repo.repo_name,
+                                          pull_request.pull_request_id,
+                                          h.canonical_hostname())]
+            if line_no: # TODO: url to file _and_ line number
+                threading.append('%s-pr-%s-line-%s@%s' % (pull_request.other_repo.repo_name,
+                                                          pull_request.pull_request_id, line_no,
+                                                          h.canonical_hostname()))
             comment_url = h.canonical_url('pullrequest_show',
                 repo_name=pull_request.other_repo.repo_name,
                 pull_request_id=pull_request.pull_request_id,
@@ -155,7 +160,7 @@
                 'repo_name': pull_request.other_repo.repo_name,
                 'ref': org_ref_name,
                 'comment_username': user.username,
-                'threading': [pr_url, comment_url], # TODO: url to line number
+                'threading': threading,
             }
 
         return subj, body, recipients, notification_type, email_kwargs
--- a/kallithea/model/pull_request.py	Tue Aug 12 13:08:23 2014 +0200
+++ b/kallithea/model/pull_request.py	Tue Aug 12 13:08:23 2014 +0200
@@ -126,6 +126,8 @@
         #notification to reviewers
         pr_url = h.canonical_url('pullrequest_show', repo_name=pr.other_repo.repo_name,
                        pull_request_id=pr.pull_request_id)
+        threading = [h.canonical_url('pullrequest_show', repo_name=pr.other_repo.repo_name,
+                                     pull_request_id=pr.pull_request_id)]
         subject = safe_unicode(
             h.link_to(
               _('%(user)s wants you to review pull request #%(pr_id)s: %(pr_title)s') % \
@@ -146,7 +148,7 @@
             'pr_id': pr.pull_request_id,
             'ref': org_ref_name,
             'pr_username': pr.author.username,
-            'threading': [pr_url],
+            'threading': threading,
             'is_mention': False,
             }
         if reviewers: