diff rhodecode/lib/middleware/simplegit.py @ 2402:2eeb2ed72e55 beta

Added handling of git hooks, extract pushed revisions and store them inside rhodecode journal. F.I.N.A.L.Y !
author Marcin Kuzminski <marcin@python-works.com>
date Wed, 06 Jun 2012 19:51:16 +0200
parents 034e4fe1ebb2
children 8a68e0292232
line wrap: on
line diff
--- a/rhodecode/lib/middleware/simplegit.py	Wed Jun 06 19:19:21 2012 +0200
+++ b/rhodecode/lib/middleware/simplegit.py	Wed Jun 06 19:51:16 2012 +0200
@@ -68,8 +68,9 @@
   'git-receive-pack': dulserver.ReceivePackHandler,
 }
 
-from dulwich.repo import Repo
-from dulwich.web import make_wsgi_chain
+# not used for now until dulwich get's fixed
+#from dulwich.repo import Repo
+#from dulwich.web import make_wsgi_chain
 
 from paste.httpheaders import REMOTE_USER, AUTH_TYPE
 
@@ -77,7 +78,7 @@
 from rhodecode.lib.base import BaseVCSController
 from rhodecode.lib.auth import get_container_username
 from rhodecode.lib.utils import is_valid_repo, make_ui
-from rhodecode.model.db import User
+from rhodecode.model.db import User, RhodeCodeUi
 
 from webob.exc import HTTPNotFound, HTTPForbidden, HTTPInternalServerError
 
@@ -205,13 +206,13 @@
             self._handle_githooks(repo_name, action, baseui, environ)
 
             log.info('%s action on GIT repo "%s"' % (action, repo_name))
-            app = self.__make_app(repo_name, repo_path)
+            app = self.__make_app(repo_name, repo_path, username)
             return app(environ, start_response)
         except Exception:
             log.error(traceback.format_exc())
             return HTTPInternalServerError()(environ, start_response)
 
-    def __make_app(self, repo_name, repo_path):
+    def __make_app(self, repo_name, repo_path, username):
         """
         Make an wsgi application using dulserver
 
@@ -223,6 +224,7 @@
         app = make_wsgi_app(
             repo_root=os.path.dirname(repo_path),
             repo_name=repo_name,
+            username=username,
         )
         return app
 
@@ -268,7 +270,10 @@
         return op
 
     def _handle_githooks(self, repo_name, action, baseui, environ):
-        from rhodecode.lib.hooks import log_pull_action, log_push_action
+        """
+        Handles pull action, push is handled by pre-receive hook
+        """
+        from rhodecode.lib.hooks import log_pull_action
         service = environ['QUERY_STRING'].split('=')
         if len(service) < 2:
             return
@@ -278,12 +283,8 @@
         _repo = _repo.scm_instance
         _repo._repo.ui = baseui
 
-        push_hook = 'pretxnchangegroup.push_logger'
-        pull_hook = 'preoutgoing.pull_logger'
         _hooks = dict(baseui.configitems('hooks')) or {}
-        if action == 'push' and _hooks.get(push_hook):
-            log_push_action(ui=baseui, repo=_repo._repo)
-        elif action == 'pull' and _hooks.get(pull_hook):
+        if action == 'pull' and _hooks.get(RhodeCodeUi.HOOK_PULL):
             log_pull_action(ui=baseui, repo=_repo._repo)
 
     def __inject_extras(self, repo_path, baseui, extras={}):