incubator-allura-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From brond...@apache.org
Subject [04/44] git commit: [#6534] ticket:416 import wiki history for github
Date Fri, 04 Oct 2013 14:42:52 GMT
[#6534]  ticket:416 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/c6f30c81
Tree: http://git-wip-us.apache.org/repos/asf/incubator-allura/tree/c6f30c81
Diff: http://git-wip-us.apache.org/repos/asf/incubator-allura/diff/c6f30c81

Branch: refs/heads/master
Commit: c6f30c8114f06493090e451defd15562cc88498a
Parents: 9472da3
Author: Yuriy Arhipov <yuriyarhipovua@yandex.ru>
Authored: Mon Sep 9 02:33:15 2013 +0400
Committer: Dave Brondsema <dbrondsema@slashdotmedia.com>
Committed: Fri Oct 4 14:21:19 2013 +0000

----------------------------------------------------------------------
 .../forgeimporters/github/tests/test_wiki.py    | 59 ++++++++++++++++----
 ForgeImporters/forgeimporters/github/wiki.py    | 32 ++++++-----
 .../forgewiki/templates/wiki/page_history.html  |  2 +-
 3 files changed, 66 insertions(+), 27 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/c6f30c81/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 e9e31e8..1f0a83b 100644
--- a/ForgeImporters/forgeimporters/github/tests/test_wiki.py
+++ b/ForgeImporters/forgeimporters/github/tests/test_wiki.py
@@ -15,6 +15,7 @@
 #       specific language governing permissions and limitations
 #       under the License.
 
+import datetime
 
 from unittest import TestCase
 from nose.tools import assert_equal
@@ -49,15 +50,51 @@ class TestGitHubWikiImporter(TestCase):
 
     def setUp(self):
         setup_basic_test()
+        self.blob1 = Mock()
+        self.blob1.name = 'Home.md'
+        self.blob1.data_stream.read.return_value = '# test message'
 
-    @patch('forgeimporters.github.wiki.GitHubWikiImporter.get_wiki_pages_form_git')
-    def test_get_wiki_pages(self, get_wiki_pages):
-        get_wiki_pages.return_value = {
-            "Home_creole.creole": "**TEST**",
-            "Home_md.md": "# TEST",
-            "Home.rest": "test"
-        }
-        data = GitHubWikiImporter().get_wiki_pages("http://test.git")
-        assert_equal(data['Home_creole'], '<p><strong>TEST</strong></p>\n')
-        assert_equal(data['Home_md'], '<div class="markdown_content"><h1 id="test">TEST</h1></div>')
-        assert_equal(data['Home'], '<div class="document">\n<p>test</p>\n</div>\n')
+        self.blob2 = Mock()
+        self.blob2.name = 'Home2.creole'
+        self.blob2.data_stream.read.return_value = '**test message**'
+
+        self.blob3 = Mock()
+        self.blob3.name = 'Home3.rest'
+        self.blob3.data_stream.read.return_value = 'test message'
+
+        self.commit1 = Mock()
+        self.commit1.tree.blobs = [self.blob1]
+        self.commit1.committed_date = 1256301446
+
+        self.commit2 = Mock()
+        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.git.Repo')
+    @patch('forgeimporters.github.wiki.mkdtemp')
+    def test_clone_from(self, path, repo):
+        with patch('forgeimporters.github.wiki.rmtree'):
+            path.return_value = 'temp_path'
+            GitHubWikiImporter().get_wiki_pages('wiki_url')
+            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):
+        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)

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/c6f30c81/ForgeImporters/forgeimporters/github/wiki.py
----------------------------------------------------------------------
diff --git a/ForgeImporters/forgeimporters/github/wiki.py b/ForgeImporters/forgeimporters/github/wiki.py
index 2dc56ca..cc9431c 100644
--- a/ForgeImporters/forgeimporters/github/wiki.py
+++ b/ForgeImporters/forgeimporters/github/wiki.py
@@ -16,13 +16,13 @@
 #       under the License.
 
 import git
+from datetime import datetime
 from tempfile import mkdtemp
 from shutil import rmtree
 
 from pylons import app_globals as g
 from pylons import tmpl_context as c
 
-
 from allura.lib import helpers as h
 from forgeimporters.base import ToolImporter
 from forgeimporters.github import GitHubProjectExtractor
@@ -61,27 +61,29 @@ class GitHubWikiImporter(ToolImporter):
             mount_label=mount_label or 'Wiki')
 
         with h.push_config(c, app=app):
-            for page_name, page_text in self.get_wiki_pages(extractor.get_page_url('wiki_url')).iteritems():
-                page = WM.Page.upsert(page_name)
-                page.text = page_text
-                page.viewable_by = ['all']
+            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()
 
         g.post_event('project_updated')
         return app
 
-    def get_wiki_pages(self, wiki_url):
+    def get_blobs(self, commit):
         result = dict()
-        wiki_pages = self.get_wiki_pages_form_git(wiki_url)
-        for page_name, page_text in wiki_pages.iteritems():
-            page_text = h.render_any_markup(page_name, h.really_unicode(page_text))
-            result[page_name.split('.')[0]] = page_text
+        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
 
-    def get_wiki_pages_form_git(self, wiki_url):
-        result = dict()
+    def get_wiki_pages(self, wiki_url):
+        result = []
         wiki_path = mkdtemp()
-        wiki = git.Repo.clone_from(wiki_url, wiki_path)
-        for page in wiki.heads.master.commit.tree.blobs:
-            result[page.name] = page.data_stream.read()
+        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))
         rmtree(wiki_path)
         return result

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/c6f30c81/ForgeWiki/forgewiki/templates/wiki/page_history.html
----------------------------------------------------------------------
diff --git a/ForgeWiki/forgewiki/templates/wiki/page_history.html b/ForgeWiki/forgewiki/templates/wiki/page_history.html
index 617b648..7edc135 100644
--- a/ForgeWiki/forgewiki/templates/wiki/page_history.html
+++ b/ForgeWiki/forgewiki/templates/wiki/page_history.html
@@ -47,7 +47,7 @@
       {% for p in pages %}
         <tr>
           <td>{{p.version}} by {{p.author.display_name}} ({{p.author.username}})</td>
-          <td>{{abbr_date(p.mod_date)}}</td>
+          <td>{{abbr_date(p.data.mod_date)}}</td>
           <td><input name="v1" type="radio" value="{{p.version}}"/></td>
           <td><input name="v2" type="radio" value="{{p.version}}"/></td>
           <td class="tright">


Mime
View raw message