incubator-allura-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tvansteenbu...@apache.org
Subject [06/50] git commit: [#6534] ticket:416 show checkbox for import wiki history for github
Date Fri, 04 Oct 2013 23:23:12 GMT
[#6534]  ticket:416 show checkbox for import wiki history for github


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

Branch: refs/heads/tv/6670
Commit: 59e7ba2a99137309a05737e714936038b2688864
Parents: c6f30c8
Author: Yuriy Arhipov <yuriyarhipovua@yandex.ru>
Authored: Tue Sep 10 11:56:53 2013 +0400
Committer: Dave Brondsema <dbrondsema@slashdotmedia.com>
Committed: Fri Oct 4 14:21:19 2013 +0000

----------------------------------------------------------------------
 ForgeImporters/forgeimporters/base.py           |  8 +++
 .../forgeimporters/github/tests/test_wiki.py    | 53 +++++++++++++-------
 ForgeImporters/forgeimporters/github/wiki.py    | 53 ++++++++++++--------
 .../forgeimporters/templates/project_base.html  |  5 ++
 .../tests/github/functional/test_github.py      |  1 +
 5 files changed, 82 insertions(+), 38 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/59e7ba2a/ForgeImporters/forgeimporters/base.py
----------------------------------------------------------------------
diff --git a/ForgeImporters/forgeimporters/base.py b/ForgeImporters/forgeimporters/base.py
index ce47dfd..9df12c3 100644
--- a/ForgeImporters/forgeimporters/base.py
+++ b/ForgeImporters/forgeimporters/base.py
@@ -399,6 +399,14 @@ class ToolImporter(object):
         return getattr(aslist(self.target_app)[0], 'tool_label', None)
 
     @property
+    def tool_option(self):
+        """
+        The label for this tool importer.  Defaults to the `tool_label` from
+        the `target_app`.
+        """
+        return getattr(aslist(self.target_app)[0], 'tool_option', dict())
+
+    @property
     def tool_description(self):
         """
         The description for this tool importer.  Defaults to the `tool_description`

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/59e7ba2a/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 1f0a83b..d37abd1 100644
--- a/ForgeImporters/forgeimporters/github/tests/test_wiki.py
+++ b/ForgeImporters/forgeimporters/github/tests/test_wiki.py
@@ -19,8 +19,7 @@ import datetime
 
 from unittest import TestCase
 from nose.tools import assert_equal
-from mock import Mock, patch
-
+from mock import Mock, patch, call
 from forgeimporters.github.wiki import GitHubWikiImporter
 from alluratest.controller import setup_basic_test
 
@@ -70,12 +69,17 @@ class TestGitHubWikiImporter(TestCase):
         self.commit2.tree.blobs = [self.blob1, self.blob2, self.blob3]
         self.commit2.committed_date = 1256291446
 
-    def test_get_blobs(self):
-        wiki = GitHubWikiImporter().get_blobs(self.commit2)
-        assert_equal(wiki['Home'][0], '<div class="markdown_content"><h1 id="test-message">test
message</h1></div>')
-        assert_equal(wiki['Home'][1], datetime.datetime(2009, 10, 23, 9, 50, 46))
-        assert_equal(wiki['Home2'][0], '<p><strong>test message</strong></p>\n')
-        assert_equal(wiki['Home3'][0], '<div class="document">\n<p>test message</p>\n</div>\n')
+    @patch('forgeimporters.github.wiki.WM.Page.upsert')
+    @patch('forgeimporters.github.wiki.h.render_any_markup')
+    def test_get_blobs_without_history(self, render, upsert):
+        upsert.text = Mock()
+        GitHubWikiImporter().get_blobs_without_history(self.commit2)
+        assert_equal(upsert.call_args_list, [call('Home'), call('Home2'), call('Home3')])
+
+        assert_equal(render.call_args_list, [
+            call('Home.md', u'# test message'),
+            call('Home2.creole', u'**test message**'),
+            call('Home3.rest', u'test message')])
 
     @patch('forgeimporters.github.wiki.git.Repo')
     @patch('forgeimporters.github.wiki.mkdtemp')
@@ -86,15 +90,28 @@ class TestGitHubWikiImporter(TestCase):
             repo.clone_from.assert_called_with('wiki_url', to_path='temp_path', bare=True)
 
     @patch('forgeimporters.github.wiki.git.Repo._clone')
-    def test_get_commits(self, clone):
+    @patch('forgeimporters.github.wiki.GitHubWikiImporter.get_blobs_with_history')
+    @patch('forgeimporters.github.wiki.GitHubWikiImporter.get_blobs_without_history')
+    def test_get_commits_with_history(self, without_history, with_history, clone):
         repo = clone.return_value
         repo.iter_commits.return_value = [self.commit1, self.commit2]
-        wiki = GitHubWikiImporter().get_wiki_pages('wiki_url')
-        assert_equal(len(wiki), 2)
-        assert_equal(wiki[0]['Home'][0], '<div class="markdown_content"><h1 id="test-message">test
message</h1></div>')
-        assert_equal(wiki[0]['Home2'][0], '<p><strong>test message</strong></p>\n')
-        assert_equal(wiki[0]['Home3'][0], '<div class="document">\n<p>test message</p>\n</div>\n')
-        assert_equal(len(wiki[0]), 3)
-
-        assert_equal(wiki[1]['Home'][0], '<div class="markdown_content"><h1 id="test-message">test
message</h1></div>')
-        assert_equal(len(wiki[1]), 1)
+        GitHubWikiImporter().get_wiki_pages('wiki_url', history=True)
+        assert_equal(with_history.call_count, 2)
+        assert_equal(without_history.call_count, 0)
+
+    @patch('forgeimporters.github.wiki.GitHubWikiImporter.get_blobs_with_history')
+    @patch('forgeimporters.github.wiki.GitHubWikiImporter.get_blobs_without_history')
+    def test_get_commits_without_history(self, without_history, with_history):
+        with patch('forgeimporters.github.wiki.git.Repo._clone'):
+            GitHubWikiImporter().get_wiki_pages('wiki_url')
+            assert_equal(with_history.call_count, 0)
+            assert_equal(without_history.call_count, 1)
+
+    @patch('forgeimporters.github.wiki.WM.Page.upsert')
+    @patch('forgeimporters.github.wiki.h.render_any_markup')
+    def test_get_blobs_with_history(self, render, upsert):
+        self.commit2.stats.files = {"Home.md": self.blob1}
+        self.commit2.tree = {"Home.md": self.blob1}
+        GitHubWikiImporter().get_blobs_with_history(self.commit2)
+        assert_equal(upsert.call_args_list, [call('Home')])
+        assert_equal(render.call_args_list, [call('Home.md', u'# test message')])
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/59e7ba2a/ForgeImporters/forgeimporters/github/wiki.py
----------------------------------------------------------------------
diff --git a/ForgeImporters/forgeimporters/github/wiki.py b/ForgeImporters/forgeimporters/github/wiki.py
index cc9431c..052364f 100644
--- a/ForgeImporters/forgeimporters/github/wiki.py
+++ b/ForgeImporters/forgeimporters/github/wiki.py
@@ -45,8 +45,10 @@ class GitHubWikiImporter(ToolImporter):
     source = 'GitHub'
     tool_label = 'Wiki'
     tool_description = 'Import your wiki from GitHub'
+    tool_option = {"history_github_wiki": "Import wiki revision history"}
 
-    def import_tool(self, project, user, project_name=None, mount_point=None, mount_label=None,
user_name=None, **kw):
+    def import_tool(self, project, user, project_name=None, mount_point=None, mount_label=None,
user_name=None,
+                    tool_option=None, **kw):
         """ Import a GitHub wiki into a new Wiki Allura tool.
 
         """
@@ -59,31 +61,42 @@ class GitHubWikiImporter(ToolImporter):
             "Wiki",
             mount_point=mount_point or 'wiki',
             mount_label=mount_label or 'Wiki')
-
+        get_wiki_with_history = tool_option == 'history_github_wiki'
         with h.push_config(c, app=app):
-            for commit in self.get_wiki_pages(extractor.get_page_url('wiki_url')):
-                for page_name, page in commit.iteritems():
-                    wiki_page = WM.Page.upsert(page_name)
-                    wiki_page.text = page[0]
-                    wiki_page.mod_date = page[1]
-                    wiki_page.timestamp = page[1]
-                    wiki_page.viewable_by = ['all']
-                    wiki_page.commit()
-
+            self.get_wiki_pages(extractor.get_page_url('wiki_url'), history=get_wiki_with_history)
         g.post_event('project_updated')
         return app
 
-    def get_blobs(self, commit):
-        result = dict()
+    def get_blobs_without_history(self, commit):
         for page in commit.tree.blobs:
-            result[page.name.split('.')[0]] = [h.render_any_markup(page.name, h.really_unicode(page.data_stream.read())),
datetime.utcfromtimestamp(commit.committed_date)]
-        return result
+            wiki_page = WM.Page.upsert(page.name.split('.')[0])
+            wiki_page.text = h.render_any_markup(page.name, h.really_unicode(page.data_stream.read()))
+            wiki_page.timestamp = wiki_page.mod_date = datetime.utcfromtimestamp(commit.committed_date)
+            wiki_page.viewable_by = ['all']
+            wiki_page.commit()
 
-    def get_wiki_pages(self, wiki_url):
-        result = []
+    def get_blobs_with_history(self, commit):
+        for page_name in commit.stats.files.keys():
+            wiki_page = WM.Page.upsert(page_name.split('.')[0])
+            if page_name in commit.tree:
+                wiki_page.text = h.render_any_markup(
+                    page_name,
+                    h.really_unicode(commit.tree[page_name].data_stream.read()))
+                wiki_page.timestamp = wiki_page.mod_date = datetime.utcfromtimestamp(commit.committed_date)
+                wiki_page.viewable_by = ['all']
+            else:
+                wiki_page.deleted = True
+                suffix = " {dt.hour}:{dt.minute}:{dt.second} {dt.day}-{dt.month}-{dt.year}".format(dt=datetime.utcnow())
+                wiki_page.title += suffix
+            wiki_page.commit()
+
+    def get_wiki_pages(self, wiki_url, history=None):
         wiki_path = mkdtemp()
         wiki = git.Repo.clone_from(wiki_url, to_path=wiki_path, bare=True)
-        for commit in wiki.iter_commits():
-            result.insert(0, self.get_blobs(commit))
+        if not history:
+            return self.get_blobs_without_history(wiki.heads.master.commit)
+
+        commits = [commit for commit in wiki.iter_commits()]
+        for commit in reversed(commits):
+            self.get_blobs_with_history(commit)
         rmtree(wiki_path)
-        return result

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/59e7ba2a/ForgeImporters/forgeimporters/templates/project_base.html
----------------------------------------------------------------------
diff --git a/ForgeImporters/forgeimporters/templates/project_base.html b/ForgeImporters/forgeimporters/templates/project_base.html
index 9453e65..4a12b1f 100644
--- a/ForgeImporters/forgeimporters/templates/project_base.html
+++ b/ForgeImporters/forgeimporters/templates/project_base.html
@@ -125,6 +125,11 @@
             <label>
                 <input name="tools" value="{{name}}" type="checkbox"{% if not c.form_errors
or name in c.form_values['tools'] %} checked="checked"{% endif %}/>
                 {{tool_importer.tool_label}}
+                {%for option_name, option_label in tool_importer.tool_option.iteritems()%}
+                    </br>
+                    <input name="tool_option" value="{{option_name}}" type="checkbox"{%
if not c.form_errors or name in c.form_values['tool_option'] %} checked="checked"{% endif
%}/>
+                    {{option_label}}
+                {%endfor%}
             </label>
             {{tool_importer.tool_description}}
         </div>

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/59e7ba2a/ForgeImporters/forgeimporters/tests/github/functional/test_github.py
----------------------------------------------------------------------
diff --git a/ForgeImporters/forgeimporters/tests/github/functional/test_github.py b/ForgeImporters/forgeimporters/tests/github/functional/test_github.py
index cee88c0..f2f93df 100644
--- a/ForgeImporters/forgeimporters/tests/github/functional/test_github.py
+++ b/ForgeImporters/forgeimporters/tests/github/functional/test_github.py
@@ -26,6 +26,7 @@ class TestGitHubImportController(TestController, TestCase):
         assert '<input id="user_name" name="user_name" value="" autofocus/>' in r
         assert '<input id="project_name" name="project_name" value="" />' in r
         assert '<input id="project_shortname" name="project_shortname" value=""/>'
in r
+        assert '<input name="tool_option" value="history_github_wiki" type="checkbox"
checked="checked"/>' in r, r
 
     def test_login_overlay(self):
         r = self.app.get('/p/import_project/github/', extra_environ=dict(username='*anonymous'))


Mime
View raw message