You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@allura.apache.org by je...@apache.org on 2015/01/08 13:15:55 UTC
allura git commit: [#7808] ticket:703 Improve GH wiki presence check
Repository: allura
Updated Branches:
refs/heads/ib/7808 [created] f08b93bf4
[#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/f08b93bf
Tree: http://git-wip-us.apache.org/repos/asf/allura/tree/f08b93bf
Diff: http://git-wip-us.apache.org/repos/asf/allura/diff/f08b93bf
Branch: refs/heads/ib/7808
Commit: f08b93bf4e98578ac534b8734e4e5493f4674eb8
Parents: 6205700
Author: Igor Bondarenko <je...@gmail.com>
Authored: Wed Jan 7 13:32:17 2015 +0000
Committer: Igor Bondarenko <je...@gmail.com>
Committed: Wed Jan 7 14:07:46 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/f08b93bf/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/f08b93bf/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)