allura-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From john...@apache.org
Subject git commit: [#6837] Translate rev links when importing from Trac
Date Fri, 15 Nov 2013 22:40:35 GMT
Updated Branches:
  refs/heads/cj/6837 [created] 0cbcbcf34


[#6837] Translate rev links when importing from Trac

Also fixed a couple of issues with handling of ticket links and
escaping brackets in link text

Signed-off-by: Cory Johns <cjohns@slashdotmedia.com>


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

Branch: refs/heads/cj/6837
Commit: 0cbcbcf34fc177872bdd69d514e8039256f67914
Parents: 2f8d344
Author: Cory Johns <cjohns@slashdotmedia.com>
Authored: Fri Nov 15 22:39:26 2013 +0000
Committer: Cory Johns <cjohns@slashdotmedia.com>
Committed: Fri Nov 15 22:39:32 2013 +0000

----------------------------------------------------------------------
 .../forgeimporters/trac/tests/test_tickets.py   | 35 ++++++++++++++------
 ForgeImporters/forgeimporters/trac/tickets.py   |  9 +++--
 2 files changed, 32 insertions(+), 12 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/0cbcbcf3/ForgeImporters/forgeimporters/trac/tests/test_tickets.py
----------------------------------------------------------------------
diff --git a/ForgeImporters/forgeimporters/trac/tests/test_tickets.py b/ForgeImporters/forgeimporters/trac/tests/test_tickets.py
index f55ac67..ca73ee6 100644
--- a/ForgeImporters/forgeimporters/trac/tests/test_tickets.py
+++ b/ForgeImporters/forgeimporters/trac/tests/test_tickets.py
@@ -154,16 +154,31 @@ class TestTracImportSupport(TestCase):
     def test_link_processing(self):
         import_support = TracImportSupport()
         import_support.get_slug_by_id = lambda ticket, comment: '123'
-        result = import_support.link_processing('''\
-                test link [[2496]](http://testlink.com)
-                test ticket ([#201](http://sourceforge.net/apps/trac/sourceforge/ticket/201))
-                Replying to [someuser](http://sourceforge.net/apps/trac/sourceforge/ticket/204#comment:1)
-                #200 unchanged''')
-
-        assert "test link [\[2496\]](http://testlink.com)" in result
-        assert 'test ticket ([#201](201))' in result
-        assert 'Replying to [someuser](204/#123)' in result
-        assert '#200 unchanged' in result, result
+        cases = {
+                'test link [[2496]](http://testlink.com)':
+                "test link [\[2496\]](http://testlink.com)",
+
+                'test ticket ([#201](http://site.net/apps/trac/project/ticket/201))':
+                'test ticket ([#201](201))',
+
+                'Replying to [someuser](http://site.net/apps/trac/project/ticket/204#comment:1)':
+                'Replying to [someuser](204/#123)',
+
+                '**description** modified ([diff](http://site.net/apps/trac/project/ticket/205?action=diff&version=1))':
+                '**description** modified ([diff](205))',
+
+                'Fixed in [r1000](http://site.net/apps/trac/project/changeset/1000)':
+                'Fixed in [r1000](r1000)',
+
+                '[[Double brackets]](1) the [[whole way]](2).':
+                '[\[Double brackets\]](1) the [\[whole way\]](2).',
+
+                '#200 unchanged':
+                '#200 unchanged',
+            }
+        for input, expected in cases.items():
+            actual = import_support.link_processing(input)
+            self.assertEqual(actual, expected)
 
 
 class TestTracImportSupportFunctional(TestRestApiBase, TestCase):

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/0cbcbcf3/ForgeImporters/forgeimporters/trac/tickets.py
----------------------------------------------------------------------
diff --git a/ForgeImporters/forgeimporters/trac/tickets.py b/ForgeImporters/forgeimporters/trac/tickets.py
index d86f965..4fd8fdf 100644
--- a/ForgeImporters/forgeimporters/trac/tickets.py
+++ b/ForgeImporters/forgeimporters/trac/tickets.py
@@ -189,6 +189,9 @@ class TracImportSupport(ImportSupport):
         else:
             return text
 
+    def changeset_link(self, m):
+        return '(r%s)' % m.group(1)
+
     def brackets_escaping(self, m):
         """Escape double brackets."""
         return '[\[%s\]]' % m.groups()[0]
@@ -203,11 +206,13 @@ class TracImportSupport(ImportSupport):
 
         """
         comment_pattern = re.compile('\[(\S*\s*\S*)\]\(\S*/(\d+\n*\d*)#comment:(\d+)\)')
-        ticket_pattern = re.compile('(?<=\])\(\S*ticket/(\d+)\)')
-        brackets_pattern = re.compile('\[\[(.*)\]\]')
+        ticket_pattern = re.compile('(?<=\])\(\S*ticket/(\d+)(?:\?[^)]*)?\)')
+        changeset_pattern = re.compile(r'(?<=\])\(\S*/changeset/(\d+)(?:\?[^]]*)?\)')
+        brackets_pattern = re.compile('\[\[([^]]*)\]\]')
 
         text = comment_pattern.sub(self.comment_link, text)
         text = ticket_pattern.sub(self.ticket_link, text)
+        text = changeset_pattern.sub(self.changeset_link, text)
         text = brackets_pattern.sub(self.brackets_escaping, text)
         return text
 


Mime
View raw message