##// END OF EJS Templates
use os.environ as a fallback for getting special info from hooks, this will allow...
marcink -
r2716:4c716671 beta
parent child Browse files
Show More
@@ -33,6 +33,7 b' from mercurial.node import nullrev'
33 33 from rhodecode.lib import helpers as h
34 34 from rhodecode.lib.utils import action_logger
35 35 from rhodecode.lib.vcs.backends.base import EmptyChangeset
36 from rhodecode.lib.compat import json
36 37
37 38
38 39 def _get_scm_size(alias, root_path):
@@ -90,12 +91,23 b' def log_pull_action(ui, repo, **kwargs):'
90 91 :param ui:
91 92 :param repo:
92 93 """
94 try:
95 rc_extras = json.loads(os.environ.get('RC_SCM_DATA', "{}"))
96 except:
97 rc_extras = {}
93 98 extras = dict(repo.ui.configitems('rhodecode_extras'))
94 username = extras['username']
95 repository = extras['repository']
96 scm = extras['scm']
99 if 'username' in extras:
100 username = extras['username']
101 repository = extras['repository']
102 scm = extras['scm']
103 elif 'username' in rc_extras:
104 username = rc_extras['username']
105 repository = rc_extras['repository']
106 scm = rc_extras['scm']
107 else:
108 raise Exception('Missing data in repo.ui and os.environ')
109
97 110 action = 'pull'
98
99 111 action_logger(username, action, repository, extras['ip'], commit=True)
100 112 # extension hook call
101 113 from rhodecode import EXTENSIONS
@@ -116,11 +128,24 b' def log_push_action(ui, repo, **kwargs):'
116 128 :param repo: repo object containing the `ui` object
117 129 """
118 130
131 try:
132 rc_extras = json.loads(os.environ.get('RC_SCM_DATA', "{}"))
133 except:
134 rc_extras = {}
135
119 136 extras = dict(repo.ui.configitems('rhodecode_extras'))
120 username = extras['username']
121 repository = extras['repository']
122 action = extras['action'] + ':%s'
123 scm = extras['scm']
137 if 'username' in extras:
138 username = extras['username']
139 repository = extras['repository']
140 scm = extras['scm']
141 elif 'username' in rc_extras:
142 username = rc_extras['username']
143 repository = rc_extras['repository']
144 scm = rc_extras['scm']
145 else:
146 raise Exception('Missing data in repo.ui and os.environ')
147
148 action = 'push' + ':%s'
124 149
125 150 if scm == 'hg':
126 151 node = kwargs['node']
@@ -81,6 +81,7 b' from rhodecode.lib.utils2 import safe_st'
81 81 from rhodecode.lib.base import BaseVCSController
82 82 from rhodecode.lib.auth import get_container_username
83 83 from rhodecode.lib.utils import is_valid_repo, make_ui
84 from rhodecode.lib.compat import json
84 85 from rhodecode.model.db import User, RhodeCodeUi
85 86
86 87 log = logging.getLogger(__name__)
@@ -122,7 +123,7 b' class SimpleGit(BaseVCSController):'
122 123 return HTTPInternalServerError()(environ, start_response)
123 124
124 125 # quick check if that dir exists...
125 if is_valid_repo(repo_name, self.basepath) is False:
126 if is_valid_repo(repo_name, self.basepath, 'git') is False:
126 127 return HTTPNotFound()(environ, start_response)
127 128
128 129 #======================================================================
@@ -190,7 +191,8 b' class SimpleGit(BaseVCSController):'
190 191 'repository': repo_name,
191 192 'scm': 'git',
192 193 }
193
194 # set the environ variables for this request
195 os.environ['RC_SCM_DATA'] = json.dumps(extras)
194 196 #===================================================================
195 197 # GIT REQUEST HANDLING
196 198 #===================================================================
@@ -40,6 +40,7 b' from rhodecode.lib.utils2 import safe_st'
40 40 from rhodecode.lib.base import BaseVCSController
41 41 from rhodecode.lib.auth import get_container_username
42 42 from rhodecode.lib.utils import make_ui, is_valid_repo, ui_sections
43 from rhodecode.lib.compat import json
43 44 from rhodecode.model.db import User
44 45
45 46
@@ -87,7 +88,7 b' class SimpleHg(BaseVCSController):'
87 88 return HTTPInternalServerError()(environ, start_response)
88 89
89 90 # quick check if that dir exists...
90 if is_valid_repo(repo_name, self.basepath) is False:
91 if is_valid_repo(repo_name, self.basepath, 'hg') is False:
91 92 return HTTPNotFound()(environ, start_response)
92 93
93 94 #======================================================================
@@ -157,7 +158,8 b' class SimpleHg(BaseVCSController):'
157 158 'repository': repo_name,
158 159 'scm': 'hg',
159 160 }
160
161 # set the environ variables for this request
162 os.environ['RC_SCM_DATA'] = json.dumps(extras)
161 163 #======================================================================
162 164 # MERCURIAL REQUEST HANDLING
163 165 #======================================================================
@@ -203,19 +203,24 b' def get_repos(path, recursive=False):'
203 203 return _get_repos(path)
204 204
205 205
206 def is_valid_repo(repo_name, base_path):
206 def is_valid_repo(repo_name, base_path, scm=None):
207 207 """
208 Returns True if given path is a valid repository False otherwise
208 Returns True if given path is a valid repository False otherwise.
209 If scm param is given also compare if given scm is the same as expected
210 from scm parameter
209 211
210 212 :param repo_name:
211 213 :param base_path:
214 :param scm:
212 215
213 216 :return True: if given path is a valid repository
214 217 """
215 218 full_path = os.path.join(safe_str(base_path), safe_str(repo_name))
216 219
217 220 try:
218 get_scm(full_path)
221 scm_ = get_scm(full_path)
222 if scm:
223 return scm_[0] == scm
219 224 return True
220 225 except VCSError:
221 226 return False
General Comments 0
You need to be logged in to leave comments. Login now