allura-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From john...@apache.org
Subject [06/50] git commit: [#6441] ticket:398 refactored hyperlinks in tickets imported from trac
Date Mon, 12 Aug 2013 16:40:51 GMT
[#6441]  ticket:398 refactored hyperlinks in tickets imported from trac


Project: http://git-wip-us.apache.org/repos/asf/incubator-allura/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-allura/commit/70ee25a6
Tree: http://git-wip-us.apache.org/repos/asf/incubator-allura/tree/70ee25a6
Diff: http://git-wip-us.apache.org/repos/asf/incubator-allura/diff/70ee25a6

Branch: refs/heads/cj/6422
Commit: 70ee25a6fe029c6443d9aca632bcf9f1972a2fb0
Parents: b3fea69
Author: Yuriy Arhipov <yuriyarhipovua@yandex.ru>
Authored: Mon Jul 22 15:09:42 2013 +0400
Committer: Tim Van Steenburgh <tvansteenburgh@gmail.com>
Committed: Wed Jul 31 12:21:14 2013 +0000

----------------------------------------------------------------------
 ForgeTracker/forgetracker/import_support.py         | 16 +++++++++++++---
 .../forgetracker/tests/functional/data/sf.json      |  4 ++--
 .../forgetracker/tests/functional/test_import.py    | 12 +++++++-----
 3 files changed, 22 insertions(+), 10 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/70ee25a6/ForgeTracker/forgetracker/import_support.py
----------------------------------------------------------------------
diff --git a/ForgeTracker/forgetracker/import_support.py b/ForgeTracker/forgetracker/import_support.py
index 268f727..8735f40 100644
--- a/ForgeTracker/forgetracker/import_support.py
+++ b/ForgeTracker/forgetracker/import_support.py
@@ -193,6 +193,7 @@ class ImportSupport(object):
                 new_f, conv = transform
                 remapped[new_f] = conv(v)
 
+        remapped['description'] = self.link_processing(remapped['description'])
         ticket_num = ticket_dict['id']
         existing_ticket = TM.Ticket.query.get(app_config_id=c.app.config._id,
                                           ticket_num=ticket_num)
@@ -215,6 +216,9 @@ class ImportSupport(object):
     def ticket_link(self, m):
         return '(%s)' % m.groups()[0]
 
+    def ticket_bracket_link(self, m):
+        return '[#%s]' % m.groups()[0]
+
     def get_slug_by_id(self, ticket, comment):
         comment = int(comment)
         ticket = TM.Ticket.query.get(app_config_id=c.app.config._id,
@@ -231,17 +235,23 @@ class ImportSupport(object):
 
     def comment_link(self, m):
         ticket, comment = m.groups()
-        return '(%s#%s)' % (ticket, self.get_slug_by_id(ticket, comment))
+        slug = self.get_slug_by_id(ticket, comment)
+        if slug:
+            return '(%s#%s)' % (ticket, self.get_slug_by_id(ticket, comment))
+        else:
+            return '\(%s#comment:%s\)' % (ticket, comment)
 
     def brackets_escaping(self, m):
-        return '[%s]' % m.groups()[0]
+        return '[\[%s\]]' % m.groups()[0]
 
     def link_processing(self, text):
+        short_link_ticket_pattern = re.compile('(?<!\[)#(\d+)(?!\])')
         comment_pattern = re.compile('\(\S*/(\d+)#comment:(\d+)\)')
         ticket_pattern = re.compile('(?<=\])\(\S*ticket/(\d+)\)')
         brackets_pattern = re.compile('\[\[(.*)\]\]')
 
-        text = comment_pattern.sub(self.comment_link, text.replace('\n', ''))
+        text = short_link_ticket_pattern.sub(self.ticket_bracket_link, text)
+        text = comment_pattern.sub(self.comment_link, text)
         text = ticket_pattern.sub(self.ticket_link, text)
         text = brackets_pattern.sub(self.brackets_escaping, text)
         return text

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/70ee25a6/ForgeTracker/forgetracker/tests/functional/data/sf.json
----------------------------------------------------------------------
diff --git a/ForgeTracker/forgetracker/tests/functional/data/sf.json b/ForgeTracker/forgetracker/tests/functional/data/sf.json
index 5a11379..82d7b89 100644
--- a/ForgeTracker/forgetracker/tests/functional/data/sf.json
+++ b/ForgeTracker/forgetracker/tests/functional/data/sf.json
@@ -44,14 +44,14 @@
             },
             {
               "class": "COMMENT",
-              "comment": "test link [[2496]](http://testlink.com)  test ticket ([#201](http://sourceforge.net/apps/trac/sourceforge/ticket/201))
\n [test comment](http://sourceforge.net/apps/trac/sourceforge/ticket/204#comment:1)",
+              "comment": "test link [[2496]](http://testlink.com)  test ticket ([#201](http://sourceforge.net/apps/trac/sourceforge/ticket/201))
\n [test comment](http://sourceforge.net/apps/trac/sourceforge/ticket/204#comment:1) \n [test
comment](http://sourceforge.net/apps/trac/sourceforge/ticket/204#comment:45)",
               "date": "2009-07-21T15:44:32Z",
               "submitter": "ctsai"
             }
           ], 
           "date": "2009-04-13T08:49:13Z", 
           "date_updated": "2009-07-20T15:44:32Z", 
-          "description": "This problem occurs with IE 7, Windows Vista:\r\nOn the project's
public info page (for example:\r\nhttps://sourceforge.net/project/admin/public_info.php?group_id=258655),
the text boxes next to \"Descriptive Name\" and \"Project Description\" are not aligned properly;
see the screenshot attached. ", 
+          "description": "This problem occurs with IE 7, Windows Vista:\r\nOn the project's
public info page (for example:\r\nhttps://sourceforge.net/project/admin/public_info.php?group_id=258655),
the text boxes next to \"Descriptive Name\" and \"Project Description\" are not aligned properly;
see the screenshot attached. ",
           "id": 204, 
           "keywords": "ENGR",
           "milestone": "test_milestone",

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/70ee25a6/ForgeTracker/forgetracker/tests/functional/test_import.py
----------------------------------------------------------------------
diff --git a/ForgeTracker/forgetracker/tests/functional/test_import.py b/ForgeTracker/forgetracker/tests/functional/test_import.py
index 202c757..1fc7331 100644
--- a/ForgeTracker/forgetracker/tests/functional/test_import.py
+++ b/ForgeTracker/forgetracker/tests/functional/test_import.py
@@ -173,12 +173,14 @@ class TestImportController(TestRestApiBase):
         import_support = ImportSupport()
         result = import_support.link_processing('''test link [[2496]](http://testlink.com)
                                        test ticket ([#201](http://sourceforge.net/apps/trac/sourceforge/ticket/201))
-                                       [test comment](http://sourceforge.net/apps/trac/sourceforge/ticket/204#comment:1)''')
+                                       [test comment](http://sourceforge.net/apps/trac/sourceforge/ticket/204#comment:1)
+                                       #200''')
 
-        assert "test link [2496](http://testlink.com)" in result
-        assert '[test comment](204#)' in result
-        assert 'test link [2496](http://testlink.com)' in result
+        assert "test link [\[2496\]](http://testlink.com)" in result
+        assert '[test comment]\(204#comment:1\)' in result
+        assert 'test link [\[2496\]](http://testlink.com)' in result
         assert 'test ticket ([#201](201))' in result
+        assert '[#200]' in result
 
     @td.with_tracker
     def test_links(self):
@@ -200,7 +202,7 @@ class TestImportController(TestRestApiBase):
             status={'$in': ['ok', 'pending']})).sort('timestamp').all()[0].slug
 
         assert '[test comment](204#%s)' % slug in r
-        assert 'test link [2496](http://testlink.com)' in r
+        assert 'test link [\[2496\]](http://testlink.com)' in r
         assert 'test ticket ([#201](201))' in r
 
     @td.with_tracker


Mime
View raw message