allura-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From john...@apache.org
Subject [06/50] git commit: [#6624] ticket:426 import_id improvemtns for GH importers
Date Tue, 22 Oct 2013 21:50:16 GMT
[#6624] ticket:426 import_id improvemtns for GH importers


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

Branch: refs/heads/cj/6422
Commit: af4521c5866690c5c7e261eadb3255f3ce04f13c
Parents: 9084bee
Author: Igor Bondarenko <jetmind2@gmail.com>
Authored: Tue Oct 8 15:52:58 2013 +0300
Committer: Tim Van Steenburgh <tvansteenburgh@gmail.com>
Committed: Mon Oct 14 15:06:04 2013 +0000

----------------------------------------------------------------------
 ForgeImporters/forgeimporters/github/code.py    |  7 ++++-
 .../forgeimporters/github/tests/test_code.py    |  3 +-
 .../forgeimporters/github/tests/test_wiki.py    | 32 ++++++++++++++++++--
 ForgeImporters/forgeimporters/github/tracker.py | 12 ++++++--
 ForgeImporters/forgeimporters/github/wiki.py    | 13 ++++++--
 .../forgeimporters/tests/github/test_tracker.py |  4 +++
 6 files changed, 62 insertions(+), 9 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/af4521c5/ForgeImporters/forgeimporters/github/code.py
----------------------------------------------------------------------
diff --git a/ForgeImporters/forgeimporters/github/code.py b/ForgeImporters/forgeimporters/github/code.py
index 848b224..1017eba 100644
--- a/ForgeImporters/forgeimporters/github/code.py
+++ b/ForgeImporters/forgeimporters/github/code.py
@@ -98,7 +98,12 @@ class GitHubRepoImporter(ToolImporter):
             "Git",
             mount_point=mount_point or 'code',
             mount_label=mount_label or 'Code',
-            init_from_url=repo_url,)
+            init_from_url=repo_url,
+            import_id={
+                'source': self.source,
+                'project_name': project_name,
+            }
+        )
         M.AuditLog.log(
                 'import tool %s from %s on %s' % (
                     app.config.options.mount_point,

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/af4521c5/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
index 5fc7fea..4ad8dac 100644
--- a/ForgeImporters/forgeimporters/github/tests/test_code.py
+++ b/ForgeImporters/forgeimporters/github/tests/test_code.py
@@ -52,7 +52,8 @@ class TestGitHubRepoImporter(TestCase):
             'Git',
             mount_point='code',
             mount_label='Code',
-            init_from_url='http://remote/clone/url/')
+            init_from_url='http://remote/clone/url/',
+            import_id={'source': 'GitHub', 'project_name': 'testuser/project_name'})
         M.AuditLog.log.assert_called_once_with(
                 'import tool code from testuser/project_name on GitHub',
                 project=p, user=u, url='foo')

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/af4521c5/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 b3f840d..d8465d5 100644
--- a/ForgeImporters/forgeimporters/github/tests/test_wiki.py
+++ b/ForgeImporters/forgeimporters/github/tests/test_wiki.py
@@ -33,7 +33,7 @@ test_project_with_wiki = 'test2'
 with_wiki = with_tool(test_project_with_wiki, 'wiki', 'w', 'wiki')
 
 
-class TestGitHubRepoImporter(TestCase):
+class TestGitHubWikiImporter(TestCase):
 
     def _make_project(self, gh_proj_name=None):
         project = Mock()
@@ -57,7 +57,12 @@ class TestGitHubRepoImporter(TestCase):
             p.install_app.assert_called_once_with(
                 'Wiki',
                 mount_point='wiki',
-                mount_label='Wiki')
+                mount_label='Wiki',
+                import_id={
+                    'source': 'GitHub',
+                    'project_name': 'testuser/project_name',
+                }
+            )
             M.AuditLog.log.assert_called_once_with(
                 'import tool wiki from testuser/project_name on GitHub',
                 project=p, user=u, url='foo')
@@ -92,6 +97,26 @@ class TestGitHubWikiImporter(TestCase):
         self.commit2.committed_date = 1256291446
 
     @patch('forgeimporters.github.wiki.WM.Page.upsert')
+    def test_import_id(self, upsert):
+        page = Mock()
+        upsert.return_value = page
+        importer = GitHubWikiImporter()
+        importer.app = Mock()
+        importer.app.config.options = {
+            'import_id': {
+                'source': 'GitHub',
+                'project_name': 'me/project',
+            }
+        }
+        importer._make_page('text', 'Page.md', self.commit2)
+        import_id = {
+            'source': 'GitHub',
+            'project_name': 'me/project',
+            'source_id': 'Page',
+        }
+        assert_equal(page.import_id, import_id)
+
+    @patch('forgeimporters.github.wiki.WM.Page.upsert')
     @patch('forgeimporters.github.wiki.h.render_any_markup')
     def test_without_history(self, render, upsert):
         self.commit2.tree.blobs = [self.blob2, self.blob3]
@@ -99,6 +124,7 @@ class TestGitHubWikiImporter(TestCase):
         importer = GitHubWikiImporter()
         importer.github_wiki_url = 'https://github.com/a/b/wiki'
         importer.app = Mock()
+        importer.app.config.options = {}
         importer.app.url = '/p/test/wiki/'
         importer.rewrite_links = Mock(return_value='')
         importer._without_history(self.commit2)
@@ -143,6 +169,7 @@ class TestGitHubWikiImporter(TestCase):
         importer._set_available_pages = Mock()
         importer.github_wiki_url = 'https://github.com/a/b/wiki'
         importer.app = Mock()
+        importer.app.config.options = {}
         importer.app.url = '/p/test/wiki/'
         importer.rewrite_links = Mock(return_value='')
         importer._with_history(self.commit2)
@@ -160,6 +187,7 @@ class TestGitHubWikiImporter(TestCase):
         importer._set_available_pages = Mock()
         importer.github_wiki_url = 'https://github.com/a/b/wiki'
         importer.app = Mock()
+        importer.app.config.options = {}
         importer.app.url = '/p/test/wiki/'
         importer.rewrite_links = Mock(return_value='')
         importer.convert_gollum_tags = Mock(return_value=u'# test message')

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/af4521c5/ForgeImporters/forgeimporters/github/tracker.py
----------------------------------------------------------------------
diff --git a/ForgeImporters/forgeimporters/github/tracker.py b/ForgeImporters/forgeimporters/github/tracker.py
index 2047946..c4153c4 100644
--- a/ForgeImporters/forgeimporters/github/tracker.py
+++ b/ForgeImporters/forgeimporters/github/tracker.py
@@ -38,6 +38,7 @@ from tg.decorators import (
 from allura import model as M
 from allura.controllers import BaseController
 from allura.lib import helpers as h
+from allura.lib.plugin import ImportIdConverter
 from allura.lib.decorators import require_post
 from ming.orm import session, ThreadLocalORMSession
 from pylons import tmpl_context as c
@@ -95,13 +96,18 @@ class GitHubTrackerImporter(ToolImporter):
 
     def import_tool(self, project, user, project_name, mount_point=None,
             mount_label=None, **kw):
+        import_id_converter = ImportIdConverter.get()
+        project_name = '%s/%s' % (kw['user_name'], project_name)
         app = project.install_app('tickets', mount_point, mount_label,
                 EnableVoting=False,
                 open_status_names='open',
                 closed_status_names='closed',
+                import_id={
+                    'source': self.source,
+                    'project_name': project_name,
+                }
             )
         ThreadLocalORMSession.flush_all()
-        project_name = '%s/%s' % (kw['user_name'], project_name)
         extractor = GitHubProjectExtractor(project_name)
         try:
             M.session.artifact_orm_session._get().skip_mod_date = True
@@ -111,7 +117,9 @@ class GitHubTrackerImporter(ToolImporter):
                     ticket = TM.Ticket(
                         app_config_id=app.config._id,
                         custom_fields=dict(),
-                        ticket_num=ticket_num)
+                        ticket_num=ticket_num,
+                        import_id=import_id_converter.expand(ticket_num, app)
+                    )
                     self.process_fields(ticket, issue)
                     self.process_comments(extractor, ticket, issue)
                     self.process_events(extractor, ticket, issue)

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/af4521c5/ForgeImporters/forgeimporters/github/wiki.py
----------------------------------------------------------------------
diff --git a/ForgeImporters/forgeimporters/github/wiki.py b/ForgeImporters/forgeimporters/github/wiki.py
index fd14f07..d95e6f0 100644
--- a/ForgeImporters/forgeimporters/github/wiki.py
+++ b/ForgeImporters/forgeimporters/github/wiki.py
@@ -40,6 +40,7 @@ from tg.decorators import (
 
 from allura.controllers import BaseController
 from allura.lib import helpers as h
+from allura.lib.plugin import ImportIdConverter
 from allura.lib.decorators import (
         require_post,
         )
@@ -141,7 +142,12 @@ class GitHubWikiImporter(ToolImporter):
         self.app = project.install_app(
             "Wiki",
             mount_point=mount_point or 'wiki',
-            mount_label=mount_label or 'Wiki')
+            mount_label=mount_label or 'Wiki',
+            import_id={
+                'source': self.source,
+                'project_name': project_name,
+            }
+        )
         with_history = tool_option == 'import_history'
         ThreadLocalORMSession.flush_all()
         try:
@@ -188,12 +194,12 @@ class GitHubWikiImporter(ToolImporter):
             self._make_page(text, filename, commit)
 
     def _make_page(self, text, filename, commit):
-        name, ext = os.path.splitext(filename)
+        orig_name, ext = os.path.splitext(filename)
         if ext and ext not in self.supported_formats:
             log.info('Not a wiki page %s. Skipping.' % filename)
             return
         mod_date = datetime.utcfromtimestamp(commit.committed_date)
-        name = self._convert_page_name(name)
+        name = self._convert_page_name(orig_name)
         wiki_page = WM.Page.upsert(name)
         if filename in commit.tree:
             wiki_page.text = self.convert_markup(h.really_unicode(text), filename)
@@ -201,6 +207,7 @@ class GitHubWikiImporter(ToolImporter):
             wiki_page.viewable_by = ['all']
         else:
             wiki_page.delete()
+        wiki_page.import_id = ImportIdConverter.get().expand(orig_name, self.app)
         wiki_page.commit()
         return wiki_page
 

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/af4521c5/ForgeImporters/forgeimporters/tests/github/test_tracker.py
----------------------------------------------------------------------
diff --git a/ForgeImporters/forgeimporters/tests/github/test_tracker.py b/ForgeImporters/forgeimporters/tests/github/test_tracker.py
index 537fe85..262ff1e 100644
--- a/ForgeImporters/forgeimporters/tests/github/test_tracker.py
+++ b/ForgeImporters/forgeimporters/tests/github/test_tracker.py
@@ -50,6 +50,10 @@ class TestTrackerImporter(TestCase):
                 EnableVoting=False,
                 open_status_names='open',
                 closed_status_names='closed',
+                import_id={
+                    'source': 'GitHub',
+                    'project_name': 'me/project_name',
+                }
             )
         gpe.iter_issues.assert_called_once()
         self.assertEqual(tlos.flush_all.call_args_list, [


Mime
View raw message