diff --git a/rhodecode/lib/middleware/simplegit.py b/rhodecode/lib/middleware/simplegit.py --- a/rhodecode/lib/middleware/simplegit.py +++ b/rhodecode/lib/middleware/simplegit.py @@ -74,7 +74,7 @@ from paste.httpheaders import REMOTE_USE from rhodecode.lib.utils2 import safe_str from rhodecode.lib.base import BaseVCSController from rhodecode.lib.auth import get_container_username -from rhodecode.lib.utils import is_valid_repo +from rhodecode.lib.utils import is_valid_repo, make_ui from rhodecode.model.db import User from webob.exc import HTTPNotFound, HTTPForbidden, HTTPInternalServerError @@ -103,6 +103,7 @@ class SimpleGit(BaseVCSController): ipaddr = self._get_ip_addr(environ) username = None + self._git_first_op = False # skip passing error to error controller environ['pylons.status_code_redirect'] = True @@ -178,6 +179,13 @@ class SimpleGit(BaseVCSController): perm = self._check_permission(action, user, repo_name) if perm is not True: return HTTPForbidden()(environ, start_response) + extras = { + 'ip': ipaddr, + 'username': username, + 'action': action, + 'repository': repo_name, + 'scm': 'git', + } #=================================================================== # GIT REQUEST HANDLING @@ -185,10 +193,16 @@ class SimpleGit(BaseVCSController): repo_path = os.path.join(safe_str(self.basepath), safe_str(repo_name)) log.debug('Repository path is %s' % repo_path) + baseui = make_ui('db') + for k, v in extras.items(): + baseui.setconfig('rhodecode_extras', k, v) + try: - #invalidate cache on push + # invalidate cache on push if action == 'push': self._invalidate_cache(repo_name) + self._handle_githooks(action, baseui, environ) + log.info('%s action on GIT repo "%s"' % (action, repo_name)) app = self.__make_app(repo_name, repo_path) return app(environ, start_response) @@ -249,3 +263,25 @@ class SimpleGit(BaseVCSController): # operation is pull/push op = getattr(self, '_git_stored_op', 'pull') return op + + def _handle_githooks(self, action, baseui, environ): + + from rhodecode.lib.hooks import log_pull_action, log_push_action + service = environ['QUERY_STRING'].split('=') + if len(service) < 2: + return + + class cont(object): + pass + + repo = cont() + setattr(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) + elif action == 'pull' and _hooks.get(pull_hook): + log_pull_action(ui=baseui, repo=repo) +