incubator-allura-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From john...@apache.org
Subject [36/50] git commit: [#6534] ticket:449 Make gollum page links case-insensitive
Date Wed, 09 Oct 2013 12:48:52 GMT
[#6534] ticket:449 Make gollum page links case-insensitive


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

Branch: refs/heads/cj/6422
Commit: 74b7854dc9785e30effad111903526b0cf933a4c
Parents: fe193f8
Author: Igor Bondarenko <jetmind2@gmail.com>
Authored: Tue Oct 1 13:50:02 2013 +0300
Committer: Dave Brondsema <dbrondsema@slashdotmedia.com>
Committed: Fri Oct 4 14:21:25 2013 +0000

----------------------------------------------------------------------
 .../forgeimporters/github/tests/test_wiki.py    | 24 ++++++++++++++++++--
 ForgeImporters/forgeimporters/github/wiki.py    | 21 +++++++++++++++++
 2 files changed, 43 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/74b7854d/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 fd3e74f..37442ef 100644
--- a/ForgeImporters/forgeimporters/github/tests/test_wiki.py
+++ b/ForgeImporters/forgeimporters/github/tests/test_wiki.py
@@ -77,8 +77,10 @@ class TestGitHubWikiImporter(TestCase):
         self.commit1.committed_date = 1256301446
 
         self.commit2 = Mock()
-        self.commit2.tree.blobs = [self.blob1, self.blob2, self.blob3]
+        blobs = [self.blob1, self.blob2, self.blob3]
+        self.commit2.tree.blobs = blobs
         self.commit2.tree.__contains__ = lambda _, item: item in [self.blob1.name, self.blob2.name,
self.blob3.name]
+        self.commit2.tree.traverse.return_value = blobs
         self.commit2.committed_date = 1256291446
 
     @patch('forgeimporters.github.wiki.WM.Page.upsert')
@@ -130,6 +132,7 @@ class TestGitHubWikiImporter(TestCase):
         self.commit2.stats.files = {"Home.rst": self.blob1}
         self.commit2.tree = {"Home.rst": self.blob1}
         importer = GitHubWikiImporter()
+        importer._set_available_pages = Mock()
         importer.github_wiki_url = 'https://github.com/a/b/wiki'
         importer.app = Mock()
         importer.app.url = '/p/test/wiki/'
@@ -138,7 +141,6 @@ class TestGitHubWikiImporter(TestCase):
         assert_equal(upsert.call_args_list, [call('Home')])
         assert_equal(render.call_args_list, [call('Home.rst', u'# test message')])
 
-
     @skipif(module_not_available('html2text'))
     @patch('forgeimporters.github.wiki.WM.Page.upsert')
     @patch('forgeimporters.github.wiki.mediawiki2markdown')
@@ -147,6 +149,7 @@ class TestGitHubWikiImporter(TestCase):
         self.commit2.tree = {"Home.mediawiki": self.blob1}
         md2mkm.return_value = u'# test message'
         importer = GitHubWikiImporter()
+        importer._set_available_pages = Mock()
         importer.github_wiki_url = 'https://github.com/a/b/wiki'
         importer.app = Mock()
         importer.app.url = '/p/test/wiki/'
@@ -156,6 +159,23 @@ class TestGitHubWikiImporter(TestCase):
         assert_equal(upsert.call_args_list, [call('Home')])
         assert_equal(md2mkm.call_args_list, [call(u'# test message')])
 
+    def test_set_available_pages(self):
+        importer = GitHubWikiImporter()
+        commit = Mock()
+        blobs = [Mock() for i in range(3)]
+        blobs[0].name = u'Home-42.md'
+        blobs[1].name = u'image.png'
+        blobs[2].name = u'code & fun.textile'
+        commit.tree.traverse.return_value = blobs
+        importer._set_available_pages(commit)
+        assert_equal(importer.available_pages, [u'Home 42', u'code & fun'])
+
+    def test_gollum_page_links_case_insensitive(self):
+        i = GitHubWikiImporter()
+        i.available_pages = [u'Home 42', u'code & fun']
+        assert_equal(i.convert_gollum_tags(u'[[Code & Fun]]'), u'[code & fun]')
+        assert_equal(i.convert_gollum_tags(u'[[home-42]]'), u'[Home 42]')
+        assert_equal(i.convert_gollum_tags(u'[[Unknown]]'), u'[Unknown]')
 
     def test_convert_page_name(self):
         f = GitHubWikiImporter()._convert_page_name

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/74b7854d/ForgeImporters/forgeimporters/github/wiki.py
----------------------------------------------------------------------
diff --git a/ForgeImporters/forgeimporters/github/wiki.py b/ForgeImporters/forgeimporters/github/wiki.py
index b041cec..d40efe8 100644
--- a/ForgeImporters/forgeimporters/github/wiki.py
+++ b/ForgeImporters/forgeimporters/github/wiki.py
@@ -134,6 +134,7 @@ class GitHubWikiImporter(ToolImporter):
             '.rst',
             '.textile',
     ] + mediawiki_exts + markdown_exts
+    available_pages = []
 
     def import_tool(self, project, user, project_name=None, mount_point=None, mount_label=None,
user_name=None,
                     tool_option=None, **kw):
@@ -165,12 +166,21 @@ class GitHubWikiImporter(ToolImporter):
         finally:
             M.session.artifact_orm_session._get().skip_mod_date = False
 
+    def _set_available_pages(self, commit):
+        pages = [blob.name for blob in commit.tree.traverse()]
+        pages = map(os.path.splitext, pages)
+        pages = [self._convert_page_name(name) for name, ext in pages
+                if ext in self.supported_formats]
+        self.available_pages = pages
+
     def _without_history(self, commit):
+        self._set_available_pages(commit)
         for page in commit.tree.blobs:
             self._make_page(page.data_stream.read(), page.name, commit)
 
     def _with_history(self, commit):
         for filename in commit.stats.files.keys():
+            self._set_available_pages(commit)
             if filename in commit.tree:
                 text = commit.tree[filename].data_stream.read()
             else:
@@ -312,6 +322,17 @@ class GitHubWikiImporter(ToolImporter):
     def _gollum_page_link(self, link, title, options):
         page = self._convert_page_name(link)
         page = page.replace(u'&amp;', u'&')  # allow & in page links
+        # gollum page lookups are case-insensitive, you'll always get link to
+        # whatever comes first in the file system, no matter how you refer to a page.
+        # E.g. if you have two pages: a.md and A.md both [[a]] and [[A]] will refer a.md.
+        # We're emulating this behavior using list of all available pages
+        try:
+            idx = map(lambda p: p.lower(), self.available_pages).index(page.lower())
+        except ValueError:
+            idx = None
+        if idx is not None:
+            page = self.available_pages[idx]
+
         if title:
             return u'[{}]({})'.format(title, page)
         return u'[{}]'.format(page)


Mime
View raw message