incubator-allura-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tvansteenbu...@apache.org
Subject [05/39] git commit: [#6533] ticket:414 Code importer for github
Date Tue, 10 Sep 2013 15:55:01 GMT
[#6533]  ticket:414 Code importer 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/61990e1f
Tree: http://git-wip-us.apache.org/repos/asf/incubator-allura/tree/61990e1f
Diff: http://git-wip-us.apache.org/repos/asf/incubator-allura/diff/61990e1f

Branch: refs/heads/db/6545
Commit: 61990e1f500d958c50ea6760828c008d3f69c78d
Parents: 56043b1
Author: Yuriy Arhipov <yuriyarhipovua@yandex.ru>
Authored: Tue Aug 27 03:36:56 2013 +0400
Committer: Tim Van Steenburgh <tvansteenburgh@gmail.com>
Committed: Mon Sep 9 14:02:08 2013 +0000

----------------------------------------------------------------------
 .../forgeimporters/github/__init__.py           |  3 ++
 ForgeImporters/forgeimporters/github/code.py    | 52 ++++++++++++++++++++
 ForgeImporters/forgeimporters/github/project.py |  1 -
 .../forgeimporters/github/tests/__init__.py     | 16 ++++++
 .../forgeimporters/github/tests/test_code.py    | 42 ++++++++++++++++
 ForgeImporters/setup.py                         |  1 +
 6 files changed, 114 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/61990e1f/ForgeImporters/forgeimporters/github/__init__.py
----------------------------------------------------------------------
diff --git a/ForgeImporters/forgeimporters/github/__init__.py b/ForgeImporters/forgeimporters/github/__init__.py
index f08f478..5cd6dc1 100644
--- a/ForgeImporters/forgeimporters/github/__init__.py
+++ b/ForgeImporters/forgeimporters/github/__init__.py
@@ -36,3 +36,6 @@ class GitHubProjectExtractor(base.ProjectExtractor):
 
     def get_homepage(self):
         return self.get_page('project_info').get('homepage')
+
+    def get_repo_url(self):
+        return self.get_page('project_info').get('clone_url')

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/61990e1f/ForgeImporters/forgeimporters/github/code.py
----------------------------------------------------------------------
diff --git a/ForgeImporters/forgeimporters/github/code.py b/ForgeImporters/forgeimporters/github/code.py
new file mode 100644
index 0000000..041a46d
--- /dev/null
+++ b/ForgeImporters/forgeimporters/github/code.py
@@ -0,0 +1,52 @@
+#       Licensed to the Apache Software Foundation (ASF) under one
+#       or more contributor license agreements.  See the NOTICE file
+#       distributed with this work for additional information
+#       regarding copyright ownership.  The ASF licenses this file
+#       to you under the Apache License, Version 2.0 (the
+#       "License"); you may not use this file except in compliance
+#       with the License.  You may obtain a copy of the License at
+#
+#         http://www.apache.org/licenses/LICENSE-2.0
+#
+#       Unless required by applicable law or agreed to in writing,
+#       software distributed under the License is distributed on an
+#       "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+#       KIND, either express or implied.  See the License for the
+#       specific language governing permissions and limitations
+#       under the License.
+
+from pylons import app_globals as g
+
+
+from forgeimporters.base import ToolImporter
+from forgeimporters.github import GitHubProjectExtractor
+
+TARGET_APPS = []
+
+try:
+    from forgegit.git_main import ForgeGitApp
+    TARGET_APPS.append(ForgeGitApp)
+except ImportError:
+    pass
+
+
+class GitHubRepoImporter(ToolImporter):
+    target_app = TARGET_APPS
+    source = 'GitHub'
+    tool_label = 'Source Code'
+    tool_description = 'Import your repo from GitHub'
+
+    def import_tool(self, project, user, project_name=None, mount_point=None, mount_label=None,
user_name=None, **kw):
+        """ Import a GitHub repo into a new Git Allura tool.
+
+        """
+        project_name = "%s/%s" % (user_name, project_name)
+        extractor = GitHubProjectExtractor(project_name)
+        repo_url = extractor.get_repo_url()
+        app = project.install_app(
+            "Git",
+            mount_point=mount_point or 'code',
+            mount_label=mount_label or 'Code',
+            init_from_url=repo_url,)
+        g.post_event('project_updated')
+        return app

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/61990e1f/ForgeImporters/forgeimporters/github/project.py
----------------------------------------------------------------------
diff --git a/ForgeImporters/forgeimporters/github/project.py b/ForgeImporters/forgeimporters/github/project.py
index 58485a7..64a499e 100644
--- a/ForgeImporters/forgeimporters/github/project.py
+++ b/ForgeImporters/forgeimporters/github/project.py
@@ -57,7 +57,6 @@ class GitHubProjectImporter(base.ProjectImporter):
     @expose()
     @validate(process_validator)
     def process(self, **kw):
-        kw['tools'] = ''
         return super(self.__class__, self).process(**kw)
 
     @expose('json:')

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/61990e1f/ForgeImporters/forgeimporters/github/tests/__init__.py
----------------------------------------------------------------------
diff --git a/ForgeImporters/forgeimporters/github/tests/__init__.py b/ForgeImporters/forgeimporters/github/tests/__init__.py
new file mode 100644
index 0000000..144e298
--- /dev/null
+++ b/ForgeImporters/forgeimporters/github/tests/__init__.py
@@ -0,0 +1,16 @@
+#       Licensed to the Apache Software Foundation (ASF) under one
+#       or more contributor license agreements.  See the NOTICE file
+#       distributed with this work for additional information
+#       regarding copyright ownership.  The ASF licenses this file
+#       to you under the Apache License, Version 2.0 (the
+#       "License"); you may not use this file except in compliance
+#       with the License.  You may obtain a copy of the License at
+#
+#         http://www.apache.org/licenses/LICENSE-2.0
+#
+#       Unless required by applicable law or agreed to in writing,
+#       software distributed under the License is distributed on an
+#       "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+#       KIND, either express or implied.  See the License for the
+#       specific language governing permissions and limitations
+#       under the License.

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/61990e1f/ForgeImporters/forgeimporters/github/tests/test_code.py
----------------------------------------------------------------------
diff --git a/ForgeImporters/forgeimporters/github/tests/test_code.py b/ForgeImporters/forgeimporters/github/tests/test_code.py
new file mode 100644
index 0000000..341e110
--- /dev/null
+++ b/ForgeImporters/forgeimporters/github/tests/test_code.py
@@ -0,0 +1,42 @@
+#       Licensed to the Apache Software Foundation (ASF) under one
+#       or more contributor license agreements.  See the NOTICE file
+#       distributed with this work for additional information
+#       regarding copyright ownership.  The ASF licenses this file
+#       to you under the Apache License, Version 2.0 (the
+#       "License"); you may not use this file except in compliance
+#       with the License.  You may obtain a copy of the License at
+#
+#         http://www.apache.org/licenses/LICENSE-2.0
+#
+#       Unless required by applicable law or agreed to in writing,
+#       software distributed under the License is distributed on an
+#       "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+#       KIND, either express or implied.  See the License for the
+#       specific language governing permissions and limitations
+#       under the License.
+
+from unittest import TestCase
+from mock import Mock, patch
+
+from forgeimporters.github.code import GitHubRepoImporter
+
+
+class TestGitHubRepoImporter(TestCase):
+
+    def _make_project(self, gh_proj_name=None):
+        project = Mock()
+        project.get_tool_data.side_effect = lambda *args: gh_proj_name
+        return project
+
+    @patch('forgeimporters.github.code.g')
+    @patch('forgeimporters.github.code.GitHubProjectExtractor')
+    def test_import_tool_happy_path(self, ghpe, g):
+        ghpe.return_value.get_repo_url.return_value = 'http://remote/clone/url/'
+        p = self._make_project(gh_proj_name='myproject')
+        GitHubRepoImporter().import_tool(p, Mock(name='c.user'), project_name='project_name',
user_name='testuser')
+        p.install_app.assert_called_once_with(
+            'Git',
+            mount_point='code',
+            mount_label='Code',
+            init_from_url='http://remote/clone/url/')
+        g.post_event.assert_called_once_with('project_updated')

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/61990e1f/ForgeImporters/setup.py
----------------------------------------------------------------------
diff --git a/ForgeImporters/setup.py b/ForgeImporters/setup.py
index d070782..bb8148b 100644
--- a/ForgeImporters/setup.py
+++ b/ForgeImporters/setup.py
@@ -41,6 +41,7 @@ setup(name='ForgeImporters',
       [allura.importers]
       google-code-tracker = forgeimporters.google.tracker:GoogleCodeTrackerImporter
       google-code-repo = forgeimporters.google.code:GoogleRepoImporter
+      github-repo = forgeimporters.github.code:GitHubRepoImporter
       trac-tickets = forgeimporters.trac.tickets:TracTicketImporter
 
       [allura.admin]


Mime
View raw message