allura-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From brond...@apache.org
Subject allura git commit: [#7808] ticket:703 Improve GH wiki presence check
Date Fri, 09 Jan 2015 18:21:27 GMT
Repository: allura
Updated Branches:
  refs/heads/master c78c0a1ba -> 184ffd645


[#7808] ticket:703 Improve GH wiki presence check


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

Branch: refs/heads/master
Commit: 184ffd6455c4e906783aab0cd02e3b4e1ee74c6a
Parents: c78c0a1
Author: Igor Bondarenko <jetmind2@gmail.com>
Authored: Wed Jan 7 13:32:17 2015 +0000
Committer: Dave Brondsema <dbrondsema@slashdotmedia.com>
Committed: Fri Jan 9 18:21:15 2015 +0000

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


http://git-wip-us.apache.org/repos/asf/allura/blob/184ffd64/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 50e7278..6523de6 100644
--- a/ForgeImporters/forgeimporters/github/tests/test_wiki.py
+++ b/ForgeImporters/forgeimporters/github/tests/test_wiki.py
@@ -21,6 +21,7 @@ from unittest import TestCase
 from nose.tools import assert_equal
 from mock import Mock, patch, call
 from ming.odm import ThreadLocalORMSession
+import git
 
 from IPython.testing.decorators import module_not_available, skipif
 from allura import model as M
@@ -50,7 +51,9 @@ class TestGitHubWikiImporter(TestCase):
     @patch('forgeimporters.github.wiki.g')
     @patch('forgeimporters.github.wiki.GitHubProjectExtractor')
     def test_import_tool_happy_path(self, ghpe, g, tlorms, M):
-        with patch('forgeimporters.github.wiki.GitHubWikiImporter.import_pages'), patch('forgeimporters.github.wiki.c'):
+        with patch('forgeimporters.github.wiki.GitHubWikiImporter.import_pages'),\
+             patch('forgeimporters.github.wiki.GitHubWikiImporter.has_wiki_repo', return_value=True),\
+             patch('forgeimporters.github.wiki.c'):
             ghpe.return_value.has_wiki.return_value = True
             p = self._make_project(gh_proj_name='myproject')
             u = Mock(name='c.user')
@@ -522,6 +525,22 @@ some text and **[Tips n' Tricks]**
         result = u'<p><strong>[[this checklist|Troubleshooting]]</strong></p>'
         assert_equal(f(source, 't.textile').strip(), result)
 
+    @patch('forgeimporters.github.wiki.mkdtemp', autospec=True)
+    @patch('forgeimporters.github.wiki.rmtree', autospec=True)
+    @patch('forgeimporters.github.wiki.git.Repo', autospec=True)
+    def test_has_wiki_repo(self, repo, rmtree, mkdtemp):
+        mkdtemp.return_value = 'fake path'
+        i = GitHubWikiImporter()
+        assert_equal(i.has_wiki_repo('fake url'), True)
+        repo.clone_from.assert_called_once_with(
+            'fake url', to_path='fake path', bare=True)
+        rmtree.assert_called_once_with('fake path')
+
+        def raise_error(*args, **kw):
+            raise git.GitCommandError('bam', 'bam', 'bam')
+        repo.clone_from.side_effect = raise_error
+        assert_equal(i.has_wiki_repo('fake url'), False)
+
 
 class TestGitHubWikiImportController(TestController, TestCase):
 

http://git-wip-us.apache.org/repos/asf/allura/blob/184ffd64/ForgeImporters/forgeimporters/github/wiki.py
----------------------------------------------------------------------
diff --git a/ForgeImporters/forgeimporters/github/wiki.py b/ForgeImporters/forgeimporters/github/wiki.py
index f2ed923..5b787d9 100644
--- a/ForgeImporters/forgeimporters/github/wiki.py
+++ b/ForgeImporters/forgeimporters/github/wiki.py
@@ -136,7 +136,11 @@ class GitHubWikiImporter(ToolImporter):
         project_name = "%s/%s" % (user_name, project_name)
         extractor = GitHubProjectExtractor(project_name, user=user)
         wiki_avail = extractor.has_wiki()
-        if not wiki_avail:
+        # has_wiki only indicates that wiki is enabled, but it does not mean
+        # that it has any pages, so we should check if wiki repo actually
+        # exists
+        wiki_url = extractor.get_page_url('wiki_url')
+        if not wiki_avail or not self.has_wiki_repo(wiki_url):
             return
 
         self.github_wiki_url = extractor.get_page_url(
@@ -158,7 +162,6 @@ class GitHubWikiImporter(ToolImporter):
             M.session.artifact_orm_session._get().skip_mod_date = True
             with h.push_config(c, app=self.app):
                 try:
-                    wiki_url = extractor.get_page_url('wiki_url')
                     self.import_pages(wiki_url, history=with_history)
                 except git.GitCommandError:
                     log.error(
@@ -254,6 +257,15 @@ class GitHubWikiImporter(ToolImporter):
         """Convert '-' and '/' into spaces in page name to match github behavior"""
         return name.replace('-', ' ').replace('/', ' ')
 
+    def has_wiki_repo(self, wiki_url):
+        wiki_path = mkdtemp()
+        try:
+            wiki = git.Repo.clone_from(wiki_url, to_path=wiki_path, bare=True)
+        except git.GitCommandError:
+            return False
+        rmtree(wiki_path)
+        return True
+
     def import_pages(self, wiki_url, history=None):
         wiki_path = mkdtemp()
         wiki = git.Repo.clone_from(wiki_url, to_path=wiki_path, bare=True)


Mime
View raw message