incubator-allura-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tvansteenbu...@apache.org
Subject [7/10] git commit: [#5308] send source_url and source_path to repo clone events
Date Tue, 20 Nov 2012 17:57:11 GMT
[#5308] send source_url and source_path to repo clone events

This refactors a few common lines from the end of each scm
implementation's clone() method into the shared init_as_clone
method.  Reduces duplication and makes the separate source_url
and source_path vars available to pass to the event.


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

Branch: refs/heads/tv/4961
Commit: aff89824d76ceee8f3fe370ce99408861b82cc9b
Parents: 6f562a5
Author: Dave Brondsema <dbrondsema@geek.net>
Authored: Thu Nov 15 22:59:09 2012 +0000
Committer: Tim Van Steenburgh <tvansteenburgh@gmail.com>
Committed: Fri Nov 16 17:14:49 2012 +0000

----------------------------------------------------------------------
 Allura/allura/model/repository.py                |    4 +++
 Allura/allura/tasks/repo_tasks.py                |    3 +-
 Allura/allura/tests/test_tasks.py                |    3 +-
 ForgeGit/forgegit/model/git_repo.py              |    3 --
 ForgeGit/forgegit/tests/model/test_repository.py |    1 -
 ForgeHg/forgehg/model/hg.py                      |    3 --
 ForgeHg/forgehg/tests/model/test_repository.py   |    1 -
 ForgeSVN/forgesvn/model/svn.py                   |    2 -
 ForgeSVN/forgesvn/tests/model/test_repository.py |   18 ++++++++++++----
 9 files changed, 20 insertions(+), 18 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/aff89824/Allura/allura/model/repository.py
----------------------------------------------------------------------
diff --git a/Allura/allura/model/repository.py b/Allura/allura/model/repository.py
index ba8df55..9867cf0 100644
--- a/Allura/allura/model/repository.py
+++ b/Allura/allura/model/repository.py
@@ -15,6 +15,7 @@ from itertools import izip
 import tg
 from paste.deploy.converters import asbool
 from pylons import c
+from pylons import app_globals as g
 import pymongo.errors
 
 from ming import schema as S
@@ -229,6 +230,9 @@ class Repository(Artifact, ActivityObject):
         session(self).flush(self)
         source = source_path if source_path else source_url
         self._impl.clone_from(source)
+        log.info('... %r cloned', self)
+        g.post_event('repo_cloned', source_url, source_path)
+        self.refresh(notify=False)
 
     def log(self, branch='master', offset=0, limit=10):
         return list(self._log(branch, offset, limit))

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/aff89824/Allura/allura/tasks/repo_tasks.py
----------------------------------------------------------------------
diff --git a/Allura/allura/tasks/repo_tasks.py b/Allura/allura/tasks/repo_tasks.py
index 152b8fb..cc074d8 100644
--- a/Allura/allura/tasks/repo_tasks.py
+++ b/Allura/allura/tasks/repo_tasks.py
@@ -29,8 +29,7 @@ def clone(cloned_from_path, cloned_from_name, cloned_from_url):
             text='Repository %s/%s created' % (
                 c.project.shortname, c.app.config.options.mount_point))
     except Exception, e:
-        source_url = cloned_from_path or cloned_from_url
-        g.post_event('repo_clone_task_failed', source_url, traceback.format_exc())
+        g.post_event('repo_clone_task_failed', cloned_from_url, cloned_from_path, traceback.format_exc())
 
 @task
 def reclone(*args, **kwargs):

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/aff89824/Allura/allura/tests/test_tasks.py
----------------------------------------------------------------------
diff --git a/Allura/allura/tests/test_tasks.py b/Allura/allura/tests/test_tasks.py
index dfecdab..bd1bc04 100644
--- a/Allura/allura/tests/test_tasks.py
+++ b/Allura/allura/tests/test_tasks.py
@@ -38,7 +38,8 @@ class TestRepoTasks(unittest.TestCase):
         repo_tasks.clone(None, None, fake_source_url)
         assert_equal(post_event.call_args[0][0], 'repo_clone_task_failed')
         assert_equal(post_event.call_args[0][1], fake_source_url)
-        # ignore args[2] which is a traceback string
+        assert_equal(post_event.call_args[0][2], None)
+        # ignore args[3] which is a traceback string
 
 
 class TestEventTasks(unittest.TestCase):

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/aff89824/ForgeGit/forgegit/model/git_repo.py
----------------------------------------------------------------------
diff --git a/ForgeGit/forgegit/model/git_repo.py b/ForgeGit/forgegit/model/git_repo.py
index 2244baa..3501e38 100644
--- a/ForgeGit/forgegit/model/git_repo.py
+++ b/ForgeGit/forgegit/model/git_repo.py
@@ -110,9 +110,6 @@ class GitImplementation(M.RepositoryImplementation):
             self._repo.status = 'ready'
             session(self._repo).flush(self._repo)
             raise
-        log.info('... %r cloned', self._repo)
-        g.post_event('repo_cloned', source_url)
-        self._repo.refresh(notify=False)
 
     def commit(self, rev):
         '''Return a Commit object.  rev can be _id or a branch/tag name'''

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/aff89824/ForgeGit/forgegit/tests/model/test_repository.py
----------------------------------------------------------------------
diff --git a/ForgeGit/forgegit/tests/model/test_repository.py b/ForgeGit/forgegit/tests/model/test_repository.py
index e31a82d..a73f07d 100644
--- a/ForgeGit/forgegit/tests/model/test_repository.py
+++ b/ForgeGit/forgegit/tests/model/test_repository.py
@@ -163,7 +163,6 @@ class TestGitRepo(unittest.TestCase, RepoImplTestBase):
             shutil.rmtree(dirname)
         repo.init()
         repo._impl.clone_from(repo_path)
-        post_event.assert_any_call('repo_cloned', repo_path)
         assert len(repo.log())
         assert not os.path.exists('/tmp/testgit.git/hooks/update')
         assert not os.path.exists('/tmp/testgit.git/hooks/post-receive-user')

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/aff89824/ForgeHg/forgehg/model/hg.py
----------------------------------------------------------------------
diff --git a/ForgeHg/forgehg/model/hg.py b/ForgeHg/forgehg/model/hg.py
index fc39d42..22d9227 100644
--- a/ForgeHg/forgehg/model/hg.py
+++ b/ForgeHg/forgehg/model/hg.py
@@ -97,9 +97,6 @@ class HgImplementation(M.RepositoryImplementation):
             self._repo.status = 'ready'
             session(self._repo).flush(self._repo)
             raise
-        log.info('... %r cloned', self._repo)
-        g.post_event('repo_cloned', source_url)
-        self._repo.refresh(notify=False)
 
     def commit(self, rev):
         '''Return a Commit object.  rev can be _id or a branch/tag name'''

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/aff89824/ForgeHg/forgehg/tests/model/test_repository.py
----------------------------------------------------------------------
diff --git a/ForgeHg/forgehg/tests/model/test_repository.py b/ForgeHg/forgehg/tests/model/test_repository.py
index 99eb814..bfb05ca 100644
--- a/ForgeHg/forgehg/tests/model/test_repository.py
+++ b/ForgeHg/forgehg/tests/model/test_repository.py
@@ -158,7 +158,6 @@ class TestHgRepo(unittest.TestCase, RepoImplTestBase):
             shutil.rmtree(dirname)
         repo.init()
         repo._impl.clone_from(repo_path)
-        post_event.assert_any_call('repo_cloned', repo_path)
         assert len(repo.log())
         assert not os.path.exists('/tmp/testrepo.hg/.hg/external-changegroup')
         assert not os.path.exists('/tmp/testrepo.hg/.hg/nested/nested-file')

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/aff89824/ForgeSVN/forgesvn/model/svn.py
----------------------------------------------------------------------
diff --git a/ForgeSVN/forgesvn/model/svn.py b/ForgeSVN/forgesvn/model/svn.py
index 2bf6b14..48d2c9c 100644
--- a/ForgeSVN/forgesvn/model/svn.py
+++ b/ForgeSVN/forgesvn/model/svn.py
@@ -186,8 +186,6 @@ class SVNImplementation(M.RepositoryImplementation):
                           c.app.config.options['checkout_url'])):
             c.app.config.options['checkout_url'] = ""
         self._setup_special_files(source_url)
-        g.post_event('repo_cloned', source_url)
-        self._repo.refresh(notify=False)
 
     def refresh_heads(self):
         info = self._svn.info2(

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/aff89824/ForgeSVN/forgesvn/tests/model/test_repository.py
----------------------------------------------------------------------
diff --git a/ForgeSVN/forgesvn/tests/model/test_repository.py b/ForgeSVN/forgesvn/tests/model/test_repository.py
index d4385fc..7d8b826 100644
--- a/ForgeSVN/forgesvn/tests/model/test_repository.py
+++ b/ForgeSVN/forgesvn/tests/model/test_repository.py
@@ -130,7 +130,6 @@ class TestSVNRepo(unittest.TestCase, RepoImplTestBase):
             shutil.rmtree(dirname)
         repo.init()
         repo._impl.clone_from('file://' + repo_path)
-        assert len(repo.log())
         assert os.path.exists('/tmp/testsvn/hooks/pre-revprop-change')
         assert os.access('/tmp/testsvn/hooks/pre-revprop-change', os.X_OK)
         with open('/tmp/testsvn/hooks/pre-revprop-change') as f: c = f.read()
@@ -142,6 +141,10 @@ class TestSVNRepo(unittest.TestCase, RepoImplTestBase):
         with open('/tmp/testsvn/hooks/post-commit') as f: c = f.read()
         self.assertIn('curl -s http://localhost//auth/refresh_repo/p/test/src/\n', c)
         self.assertIn('exec $DIR/post-commit-user "$@"\n', c)
+
+        repo.refresh(notify=False)
+        assert len(repo.log())
+
         shutil.rmtree(dirname)
 
     @mock.patch('forgesvn.model.svn.g.post_event')
@@ -159,8 +162,6 @@ class TestSVNRepo(unittest.TestCase, RepoImplTestBase):
             shutil.rmtree(dirname)
         repo.init()
         repo._impl.clone_from('file://' + repo_path)
-        post_event.assert_any_call('repo_cloned', 'file://' + repo_path)
-        assert len(repo.log())
         assert os.path.exists('/tmp/testsvn/hooks/pre-revprop-change')
         assert os.access('/tmp/testsvn/hooks/pre-revprop-change', os.X_OK)
         with open('/tmp/testsvn/hooks/pre-revprop-change') as f: c = f.read()
@@ -172,6 +173,10 @@ class TestSVNRepo(unittest.TestCase, RepoImplTestBase):
         with open('/tmp/testsvn/hooks/post-commit') as f: c = f.read()
         self.assertIn('curl -s http://localhost//auth/refresh_repo/p/test/src/\n', c)
         self.assertIn('exec $DIR/post-commit-user "$@"\n', c)
+
+        repo.refresh(notify=False)
+        assert len(repo.log())
+
         shutil.rmtree(dirname)
 
     def test_index(self):
@@ -330,7 +335,7 @@ class _Test(unittest.TestCase):
         ThreadLocalORMSession.flush_all()
         ThreadLocalORMSession.close_all()
         self.prefix = tg.config.get('scm.repos.root', '/')
-        
+
 class _TestWithRepo(_Test):
     def setUp(self):
         super(_TestWithRepo, self).setUp()
@@ -383,11 +388,13 @@ class TestRepo(_TestWithRepo):
             self.repo.url_for_commit('a'*40),
             '/p/test/test1/ci/aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/')
 
-    def test_init_as_clone(self):
+    @mock.patch('allura.model.repository.g.post_event')
+    def test_init_as_clone(self, post_event):
         self.repo.init_as_clone('srcpath', 'srcname', 'srcurl')
         assert self.repo.upstream_repo.name == 'srcname'
         assert self.repo.upstream_repo.url == 'srcurl'
         assert self.repo._impl.clone_from.called_with('srcpath')
+        post_event.assert_called_once_with('repo_cloned', 'srcurl', 'srcpath')
 
     @mock.patch.object(M.repo.CommitRunDoc.m, 'get')
     def test_log(self, crd):
@@ -520,6 +527,7 @@ class TestMergeRequest(_TestWithRepoAndCommit):
         self.repo2 = M.Repository(name='test2', tool='svn')
         self.repo2._impl = mock.Mock(spec=M.RepositoryImplementation())
         self.repo2._impl.log = lambda *a,**kw:(['foo'], [])
+        self.repo2._impl.all_commit_ids = lambda *a,**kw: []
         self.repo2._impl._repo = self.repo2
         self.repo2.init_as_clone('/p/test/', 'test1', '/p/test/test1/')
         ThreadLocalORMSession.flush_all()


Mime
View raw message