diff --git a/rhodecode/lib/hooks.py b/rhodecode/lib/hooks.py --- a/rhodecode/lib/hooks.py +++ b/rhodecode/lib/hooks.py @@ -207,15 +207,17 @@ def log_push_action(ui, repo, **kwargs): repository = extras['repository'] scm = extras['scm'] make_lock = extras['make_lock'] + action = extras['action'] elif 'username' in rc_extras: username = rc_extras['username'] repository = rc_extras['repository'] scm = rc_extras['scm'] make_lock = rc_extras['make_lock'] + action = extras['action'] else: raise Exception('Missing data in repo.ui and os.environ') - action = 'push' + ':%s' + action = action + ':%s' if scm == 'hg': node = kwargs['node'] diff --git a/rhodecode/model/scm.py b/rhodecode/model/scm.py --- a/rhodecode/model/scm.py +++ b/rhodecode/model/scm.py @@ -44,13 +44,14 @@ from rhodecode.lib.vcs.backends.base imp from rhodecode import BACKENDS from rhodecode.lib import helpers as h -from rhodecode.lib.utils2 import safe_str, safe_unicode +from rhodecode.lib.utils2 import safe_str, safe_unicode, get_server_url from rhodecode.lib.auth import HasRepoPermissionAny, HasReposGroupPermissionAny from rhodecode.lib.utils import get_filesystem_repos, make_ui, \ action_logger, REMOVED_REPO_PAT from rhodecode.model import BaseModel from rhodecode.model.db import Repository, RhodeCodeUi, CacheInvalidation, \ UserFollowing, UserLog, User, RepoGroup, PullRequest +from rhodecode.lib.hooks import log_push_action log = logging.getLogger(__name__) @@ -402,6 +403,31 @@ class ScmModel(BaseModel): self.sa.add(repo) return repo + def _handle_push(self, repo, username, action, repo_name, repo_scm, revisions): + from rhodecode import CONFIG + from rhodecode.lib.base import _get_ip_addr + from pylons import request + environ = request.environ + + #trigger push hook + extras = { + 'ip': _get_ip_addr(environ), + 'username': username, + 'action': 'push_local', + 'repository': repo_name, + 'scm': repo_scm, + 'config': CONFIG['__file__'], + 'server_url': get_server_url(environ), + 'make_lock': None, + 'locked_by': [None, None] + } + _scm_repo = repo._repo + repo.inject_ui(**extras) + if repo_scm == 'hg': + log_push_action(_scm_repo.ui, _scm_repo, node=revisions[0]) + elif repo_scm == 'git': + log_push_action(_scm_repo.ui, _scm_repo, _git_revs=revisions) + def pull_changes(self, repo, username): dbrepo = self.__get_repo(repo) clone_uri = dbrepo.clone_uri @@ -409,26 +435,13 @@ class ScmModel(BaseModel): raise Exception("This repository doesn't have a clone uri") repo = dbrepo.scm_instance - from rhodecode import CONFIG + repo_name = dbrepo.repo_name try: - extras = { - 'ip': '', - 'username': username, - 'action': 'push_remote', - 'repository': dbrepo.repo_name, - 'scm': repo.alias, - 'config': CONFIG['__file__'], - 'make_lock': None, - 'locked_by': [None, None] - } - - Repository.inject_ui(repo, extras=extras) - if repo.alias == 'git': repo.fetch(clone_uri) else: repo.pull(clone_uri) - self.mark_for_invalidation(dbrepo.repo_name) + self.mark_for_invalidation(repo_name) except: log.error(traceback.format_exc()) raise @@ -441,7 +454,6 @@ class ScmModel(BaseModel): :param repo: SCM instance """ - if repo.alias == 'hg': from rhodecode.lib.vcs.backends.hg import \ MercurialInMemoryChangeset as IMC @@ -463,9 +475,13 @@ class ScmModel(BaseModel): author=author, parents=[cs], branch=cs.branch) - action = 'push_local:%s' % tip.raw_id - action_logger(user, action, repo_name) self.mark_for_invalidation(repo_name) + self._handle_push(repo, + username=user.username, + action='push_local', + repo_name=repo_name, + repo_scm=repo.alias, + revisions=[tip.raw_id]) return tip def create_node(self, repo, repo_name, cs, user, author, message, content, @@ -502,9 +518,13 @@ class ScmModel(BaseModel): author=author, parents=parents, branch=cs.branch) - action = 'push_local:%s' % tip.raw_id - action_logger(user, action, repo_name) self.mark_for_invalidation(repo_name) + self._handle_push(repo, + username=user.username, + action='push_local', + repo_name=repo_name, + repo_scm=repo.alias, + revisions=[tip.raw_id]) return tip def get_nodes(self, repo_name, revision, root_path='/', flat=True):