incubator-allura-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tvansteenbu...@apache.org
Subject [04/50] git commit: [#6624] ticket:426 Audit log improvements to GH importer
Date Wed, 23 Oct 2013 12:56:41 GMT
[#6624] ticket:426 Audit log improvements to GH importer


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

Branch: refs/heads/tv/6610
Commit: 9084bee7fed537ae4f1fb87a3737ed96d5dd936e
Parents: 3679862
Author: Igor Bondarenko <jetmind2@gmail.com>
Authored: Fri Oct 4 19:44:03 2013 +0300
Committer: Tim Van Steenburgh <tvansteenburgh@gmail.com>
Committed: Mon Oct 14 15:06:04 2013 +0000

----------------------------------------------------------------------
 ForgeImporters/forgeimporters/github/code.py            |  9 ++++++++-
 ForgeImporters/forgeimporters/github/tests/test_code.py | 12 ++++++++++--
 ForgeImporters/forgeimporters/github/tests/test_wiki.py | 12 ++++++++++--
 ForgeImporters/forgeimporters/github/tracker.py         | 10 +++++++---
 ForgeImporters/forgeimporters/github/wiki.py            |  8 ++++++++
 .../forgeimporters/tests/github/test_tracker.py         |  5 +++++
 6 files changed, 48 insertions(+), 8 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/9084bee7/ForgeImporters/forgeimporters/github/code.py
----------------------------------------------------------------------
diff --git a/ForgeImporters/forgeimporters/github/code.py b/ForgeImporters/forgeimporters/github/code.py
index 42e847d..848b224 100644
--- a/ForgeImporters/forgeimporters/github/code.py
+++ b/ForgeImporters/forgeimporters/github/code.py
@@ -31,6 +31,7 @@ from tg.decorators import (
 
 from allura.lib.decorators import require_post
 from allura.controllers import BaseController
+from allura import model as M
 
 from forgegit.git_main import ForgeGitApp
 
@@ -85,7 +86,8 @@ class GitHubRepoImporter(ToolImporter):
     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):
+    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.
 
         """
@@ -97,5 +99,10 @@ class GitHubRepoImporter(ToolImporter):
             mount_point=mount_point or 'code',
             mount_label=mount_label or 'Code',
             init_from_url=repo_url,)
+        M.AuditLog.log(
+                'import tool %s from %s on %s' % (
+                    app.config.options.mount_point,
+                    project_name, self.source,
+                ), project=project, user=user, url=app.url)
         g.post_event('project_updated')
         return app

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/9084bee7/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 2c53e46..5fc7fea 100644
--- a/ForgeImporters/forgeimporters/github/tests/test_code.py
+++ b/ForgeImporters/forgeimporters/github/tests/test_code.py
@@ -37,17 +37,25 @@ class TestGitHubRepoImporter(TestCase):
         project.get_tool_data.side_effect = lambda *args: gh_proj_name
         return project
 
+    @patch('forgeimporters.github.code.M')
     @patch('forgeimporters.github.code.g')
     @patch('forgeimporters.github.code.GitHubProjectExtractor')
-    def test_import_tool_happy_path(self, ghpe, g):
+    def test_import_tool_happy_path(self, ghpe, g, M):
         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')
+        u = Mock(name='c.user')
+        app = p.install_app.return_value
+        app.config.options.mount_point = 'code'
+        app.url = 'foo'
+        GitHubRepoImporter().import_tool(p, u, 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/')
+        M.AuditLog.log.assert_called_once_with(
+                'import tool code from testuser/project_name on GitHub',
+                project=p, user=u, url='foo')
         g.post_event.assert_called_once_with('project_updated')
 
 

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/9084bee7/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 13d62ae..b3f840d 100644
--- a/ForgeImporters/forgeimporters/github/tests/test_wiki.py
+++ b/ForgeImporters/forgeimporters/github/tests/test_wiki.py
@@ -41,18 +41,26 @@ class TestGitHubRepoImporter(TestCase):
         return project
 
 
+    @patch('forgeimporters.github.wiki.M')
     @patch('forgeimporters.github.wiki.ThreadLocalORMSession')
     @patch('forgeimporters.github.wiki.g')
     @patch('forgeimporters.github.wiki.GitHubProjectExtractor')
-    def test_import_tool_happy_path(self, ghpe, g, tlorms):
+    def test_import_tool_happy_path(self, ghpe, g, tlorms, M):
         with patch('forgeimporters.github.wiki.GitHubWikiImporter.import_pages'), patch('forgeimporters.github.wiki.c'):
             ghpe.return_value.has_wiki.return_value = True
             p = self._make_project(gh_proj_name='myproject')
-            GitHubWikiImporter().import_tool(p, Mock(name='c.user'), project_name='project_name',
user_name='testuser')
+            u = Mock(name='c.user')
+            app = p.install_app.return_value
+            app.config.options.mount_point = 'wiki'
+            app.url = 'foo'
+            GitHubWikiImporter().import_tool(p, u, project_name='project_name', user_name='testuser')
             p.install_app.assert_called_once_with(
                 'Wiki',
                 mount_point='wiki',
                 mount_label='Wiki')
+            M.AuditLog.log.assert_called_once_with(
+                'import tool wiki from testuser/project_name on GitHub',
+                project=p, user=u, url='foo')
             g.post_event.assert_called_once_with('project_updated')
 
 

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/9084bee7/ForgeImporters/forgeimporters/github/tracker.py
----------------------------------------------------------------------
diff --git a/ForgeImporters/forgeimporters/github/tracker.py b/ForgeImporters/forgeimporters/github/tracker.py
index 7adc00c..2047946 100644
--- a/ForgeImporters/forgeimporters/github/tracker.py
+++ b/ForgeImporters/forgeimporters/github/tracker.py
@@ -101,9 +101,8 @@ class GitHubTrackerImporter(ToolImporter):
                 closed_status_names='closed',
             )
         ThreadLocalORMSession.flush_all()
-        extractor = GitHubProjectExtractor(
-            '{}/{}'.format(kw['user_name'],project_name),
-        )
+        project_name = '%s/%s' % (kw['user_name'], project_name)
+        extractor = GitHubProjectExtractor(project_name)
         try:
             M.session.artifact_orm_session._get().skip_mod_date = True
             with h.push_config(c, user=M.User.anonymous(), app=app):
@@ -122,6 +121,11 @@ class GitHubTrackerImporter(ToolImporter):
                 app.globals.custom_fields = self.postprocess_milestones()
                 app.globals.last_ticket_num = self.max_ticket_num
                 ThreadLocalORMSession.flush_all()
+            M.AuditLog.log(
+                    'import tool %s from %s on %s' % (
+                        app.config.options.mount_point,
+                        project_name, self.source),
+                    project=project, user=user, url=app.url)
             g.post_event('project_updated')
             app.globals.invalidate_bin_counts()
             return app

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/9084bee7/ForgeImporters/forgeimporters/github/wiki.py
----------------------------------------------------------------------
diff --git a/ForgeImporters/forgeimporters/github/wiki.py b/ForgeImporters/forgeimporters/github/wiki.py
index a039d5c..fd14f07 100644
--- a/ForgeImporters/forgeimporters/github/wiki.py
+++ b/ForgeImporters/forgeimporters/github/wiki.py
@@ -149,6 +149,14 @@ class GitHubWikiImporter(ToolImporter):
             with h.push_config(c, app=self.app):
                 self.import_pages(extractor.get_page_url('wiki_url'), history=with_history)
             ThreadLocalORMSession.flush_all()
+            M.AuditLog.log(
+                'import tool %s from %s on %s' % (
+                    self.app.config.options.mount_point,
+                    project_name,
+                    self.source),
+                project=project,
+                user=user,
+                url=self.app.url)
             g.post_event('project_updated')
             return self.app
         except Exception as e:

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/9084bee7/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 876c71e..537fe85 100644
--- a/ForgeImporters/forgeimporters/tests/github/test_tracker.py
+++ b/ForgeImporters/forgeimporters/tests/github/test_tracker.py
@@ -39,6 +39,8 @@ class TestTrackerImporter(TestCase):
         importer.postprocess_milestones= mock.Mock()
         project, user = mock.Mock(), mock.Mock()
         app = project.install_app.return_value
+        app.config.options.mount_point = 'mount_point'
+        app.url = 'foo'
         gpe.iter_issues.return_value = [(50, mock.Mock()), (100, mock.Mock())]
 
         importer.import_tool(project, user, project_name='project_name',
@@ -54,6 +56,9 @@ class TestTrackerImporter(TestCase):
                 mock.call(),
                 mock.call(),
             ])
+        M.AuditLog.log.assert_called_once_with(
+                'import tool mount_point from me/project_name on GitHub',
+                project=project, user=user, url='foo')
         g.post_event.assert_called_once_with('project_updated')
         app.globals.invalidate_bin_counts.assert_called_once_with()
 


Mime
View raw message