incubator-allura-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From john...@apache.org
Subject [38/50] git commit: [#6534] ticket:442 Fix links rewriter for mediawiki
Date Fri, 04 Oct 2013 18:07:22 GMT
[#6534] ticket:442 Fix links rewriter for mediawiki


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

Branch: refs/heads/cj/6692
Commit: 54a8ce76032d8c7290c871589af7c2c4a1878d8c
Parents: 889db6c
Author: Igor Bondarenko <jetmind2@gmail.com>
Authored: Thu Sep 26 17:31:25 2013 +0300
Committer: Dave Brondsema <dbrondsema@slashdotmedia.com>
Committed: Fri Oct 4 14:21:24 2013 +0000

----------------------------------------------------------------------
 .../forgeimporters/github/tests/test_wiki.py     | 19 ++++++++++---------
 ForgeImporters/forgeimporters/github/wiki.py     | 13 ++++++++++++-
 2 files changed, 22 insertions(+), 10 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/54a8ce76/ForgeImporters/forgeimporters/github/tests/test_wiki.py
----------------------------------------------------------------------
diff --git a/ForgeImporters/forgeimporters/github/tests/test_wiki.py b/ForgeImporters/forgeimporters/github/tests/test_wiki.py
index b53dab5..1809ac1 100644
--- a/ForgeImporters/forgeimporters/github/tests/test_wiki.py
+++ b/ForgeImporters/forgeimporters/github/tests/test_wiki.py
@@ -145,12 +145,13 @@ class TestGitHubWikiImporter(TestCase):
     def test_with_history_mediawiki(self, md2mkm, upsert):
         self.commit2.stats.files = {"Home.mediawiki": self.blob1}
         self.commit2.tree = {"Home.mediawiki": self.blob1}
+        md2mkm.return_value = u'# test message'
         importer = GitHubWikiImporter()
         importer.github_wiki_url = 'https://github.com/a/b/wiki'
         importer.app = Mock()
         importer.app.url = '/p/test/wiki/'
         importer.rewrite_links = Mock(return_value='')
-        importer.convert_gollum_tags = Mock()
+        importer.convert_gollum_tags = Mock(return_value=u'# test message')
         importer._with_history(self.commit2)
         assert_equal(upsert.call_args_list, [call('Home')])
         assert_equal(md2mkm.call_args_list, [call(u'# test message')])
@@ -311,19 +312,19 @@ Our website is [[http://sf.net]].
         source = u'''
 ''Al'fredas 235 BC''
 == See also ==
-* [https://github/a/b/wiki/AgentSpring-running-instructions-for-d13n-model Test1]
-* [https://github/a/b/wiki/AgentSpring-conventions Test2]
-* [https://github/a/b/wiki/AgentSpring-Q&A Test3]
-* [https://github/a/b/wiki/Extensions Test4]'''
+* [https://github.com/a/b/wiki/AgentSpring-running-instructions-for-d13n-model Test1]
+* [https://github.com/a/b/wiki/AgentSpring-conventions Test2]
+* [https://github.com/a/b/wiki/AgentSpring-Q&A Test3]
+* [https://github.com/a/b/wiki/Extensions Test4]'''
 
         result = u'''_Al'fredas 235 BC_
 
 ## See also
 
-  * [Test1](https://github/a/b/wiki/AgentSpring-running-instructions-for-d13n-model)
-  * [Test2](https://github/a/b/wiki/AgentSpring-conventions)
-  * [Test3](https://github/a/b/wiki/AgentSpring-Q&A)
-  * [Test4](https://github/a/b/wiki/Extensions)
+  * [Test1](/p/test/wiki/AgentSpring running instructions for d13n model)
+  * [Test2](/p/test/wiki/AgentSpring conventions)
+  * [Test3](/p/test/wiki/AgentSpring Q&A)
+  * [Test4](/p/test/wiki/Extensions)
 '''
 
         assert_equal(f(source, 'test.mediawiki'), result)

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/54a8ce76/ForgeImporters/forgeimporters/github/wiki.py
----------------------------------------------------------------------
diff --git a/ForgeImporters/forgeimporters/github/wiki.py b/ForgeImporters/forgeimporters/github/wiki.py
index 87a09e6..980bb64 100644
--- a/ForgeImporters/forgeimporters/github/wiki.py
+++ b/ForgeImporters/forgeimporters/github/wiki.py
@@ -248,7 +248,18 @@ class GitHubWikiImporter(ToolImporter):
             if html2text:
                 text = mediawiki2markdown(text)
                 text = self.convert_gollum_tags(text)
-                text = text.replace(self.github_wiki_url, self.app.url)
+                # Don't have html here, so we can't call self._rewrite_links.
+                # Falling back to simpler rewriter.
+                prefix = self.github_wiki_url
+                new_prefix = self.app.url
+                if not prefix.endswith('/'):
+                    prefix += '/'
+                if not new_prefix.endswith('/'):
+                    new_prefix += '/'
+                _re = re.compile(r'%s(\S*)' % prefix)
+                def repl(m):
+                    return new_prefix + self._convert_page_name(m.group(1))
+                text = _re.sub(repl, text)
             else:
                 text = h.render_any_markup(filename, text)
                 text = self.rewrite_links(text, self.github_wiki_url, self.app.url)


Mime
View raw message