diff --git a/rhodecode/lib/hooks.py b/rhodecode/lib/hooks.py --- a/rhodecode/lib/hooks.py +++ b/rhodecode/lib/hooks.py @@ -33,6 +33,7 @@ from mercurial.node import nullrev from rhodecode.lib import helpers as h from rhodecode.lib.utils import action_logger from rhodecode.lib.vcs.backends.base import EmptyChangeset +from rhodecode.lib.compat import json def _get_scm_size(alias, root_path): @@ -90,12 +91,23 @@ def log_pull_action(ui, repo, **kwargs): :param ui: :param repo: """ + try: + rc_extras = json.loads(os.environ.get('RC_SCM_DATA', "{}")) + except: + rc_extras = {} extras = dict(repo.ui.configitems('rhodecode_extras')) - username = extras['username'] - repository = extras['repository'] - scm = extras['scm'] + if 'username' in extras: + username = extras['username'] + repository = extras['repository'] + scm = extras['scm'] + elif 'username' in rc_extras: + username = rc_extras['username'] + repository = rc_extras['repository'] + scm = rc_extras['scm'] + else: + raise Exception('Missing data in repo.ui and os.environ') + action = 'pull' - action_logger(username, action, repository, extras['ip'], commit=True) # extension hook call from rhodecode import EXTENSIONS @@ -116,11 +128,24 @@ def log_push_action(ui, repo, **kwargs): :param repo: repo object containing the `ui` object """ + try: + rc_extras = json.loads(os.environ.get('RC_SCM_DATA', "{}")) + except: + rc_extras = {} + extras = dict(repo.ui.configitems('rhodecode_extras')) - username = extras['username'] - repository = extras['repository'] - action = extras['action'] + ':%s' - scm = extras['scm'] + if 'username' in extras: + username = extras['username'] + repository = extras['repository'] + scm = extras['scm'] + elif 'username' in rc_extras: + username = rc_extras['username'] + repository = rc_extras['repository'] + scm = rc_extras['scm'] + else: + raise Exception('Missing data in repo.ui and os.environ') + + action = 'push' + ':%s' if scm == 'hg': node = kwargs['node'] 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 @@ -81,6 +81,7 @@ from rhodecode.lib.utils2 import safe_st 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.lib.compat import json from rhodecode.model.db import User, RhodeCodeUi log = logging.getLogger(__name__) @@ -122,7 +123,7 @@ class SimpleGit(BaseVCSController): return HTTPInternalServerError()(environ, start_response) # quick check if that dir exists... - if is_valid_repo(repo_name, self.basepath) is False: + if is_valid_repo(repo_name, self.basepath, 'git') is False: return HTTPNotFound()(environ, start_response) #====================================================================== @@ -190,7 +191,8 @@ class SimpleGit(BaseVCSController): 'repository': repo_name, 'scm': 'git', } - + # set the environ variables for this request + os.environ['RC_SCM_DATA'] = json.dumps(extras) #=================================================================== # GIT REQUEST HANDLING #=================================================================== diff --git a/rhodecode/lib/middleware/simplehg.py b/rhodecode/lib/middleware/simplehg.py --- a/rhodecode/lib/middleware/simplehg.py +++ b/rhodecode/lib/middleware/simplehg.py @@ -40,6 +40,7 @@ from rhodecode.lib.utils2 import safe_st from rhodecode.lib.base import BaseVCSController from rhodecode.lib.auth import get_container_username from rhodecode.lib.utils import make_ui, is_valid_repo, ui_sections +from rhodecode.lib.compat import json from rhodecode.model.db import User @@ -87,7 +88,7 @@ class SimpleHg(BaseVCSController): return HTTPInternalServerError()(environ, start_response) # quick check if that dir exists... - if is_valid_repo(repo_name, self.basepath) is False: + if is_valid_repo(repo_name, self.basepath, 'hg') is False: return HTTPNotFound()(environ, start_response) #====================================================================== @@ -157,7 +158,8 @@ class SimpleHg(BaseVCSController): 'repository': repo_name, 'scm': 'hg', } - + # set the environ variables for this request + os.environ['RC_SCM_DATA'] = json.dumps(extras) #====================================================================== # MERCURIAL REQUEST HANDLING #====================================================================== diff --git a/rhodecode/lib/utils.py b/rhodecode/lib/utils.py --- a/rhodecode/lib/utils.py +++ b/rhodecode/lib/utils.py @@ -203,19 +203,24 @@ def get_repos(path, recursive=False): return _get_repos(path) -def is_valid_repo(repo_name, base_path): +def is_valid_repo(repo_name, base_path, scm=None): """ - Returns True if given path is a valid repository False otherwise + Returns True if given path is a valid repository False otherwise. + If scm param is given also compare if given scm is the same as expected + from scm parameter :param repo_name: :param base_path: + :param scm: :return True: if given path is a valid repository """ full_path = os.path.join(safe_str(base_path), safe_str(repo_name)) try: - get_scm(full_path) + scm_ = get_scm(full_path) + if scm: + return scm_[0] == scm return True except VCSError: return False