Mercurial > kallithea
comparison 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 |
comparison
equal
deleted
inserted
replaced
2401:e2af60e480ce | 2402:2eeb2ed72e55 |
---|---|
66 'git-upload-pack': SimpleGitUploadPackHandler, | 66 'git-upload-pack': SimpleGitUploadPackHandler, |
67 #git-push | 67 #git-push |
68 'git-receive-pack': dulserver.ReceivePackHandler, | 68 'git-receive-pack': dulserver.ReceivePackHandler, |
69 } | 69 } |
70 | 70 |
71 from dulwich.repo import Repo | 71 # not used for now until dulwich get's fixed |
72 from dulwich.web import make_wsgi_chain | 72 #from dulwich.repo import Repo |
73 #from dulwich.web import make_wsgi_chain | |
73 | 74 |
74 from paste.httpheaders import REMOTE_USER, AUTH_TYPE | 75 from paste.httpheaders import REMOTE_USER, AUTH_TYPE |
75 | 76 |
76 from rhodecode.lib.utils2 import safe_str | 77 from rhodecode.lib.utils2 import safe_str |
77 from rhodecode.lib.base import BaseVCSController | 78 from rhodecode.lib.base import BaseVCSController |
78 from rhodecode.lib.auth import get_container_username | 79 from rhodecode.lib.auth import get_container_username |
79 from rhodecode.lib.utils import is_valid_repo, make_ui | 80 from rhodecode.lib.utils import is_valid_repo, make_ui |
80 from rhodecode.model.db import User | 81 from rhodecode.model.db import User, RhodeCodeUi |
81 | 82 |
82 from webob.exc import HTTPNotFound, HTTPForbidden, HTTPInternalServerError | 83 from webob.exc import HTTPNotFound, HTTPForbidden, HTTPInternalServerError |
83 | 84 |
84 log = logging.getLogger(__name__) | 85 log = logging.getLogger(__name__) |
85 | 86 |
203 if action == 'push': | 204 if action == 'push': |
204 self._invalidate_cache(repo_name) | 205 self._invalidate_cache(repo_name) |
205 self._handle_githooks(repo_name, action, baseui, environ) | 206 self._handle_githooks(repo_name, action, baseui, environ) |
206 | 207 |
207 log.info('%s action on GIT repo "%s"' % (action, repo_name)) | 208 log.info('%s action on GIT repo "%s"' % (action, repo_name)) |
208 app = self.__make_app(repo_name, repo_path) | 209 app = self.__make_app(repo_name, repo_path, username) |
209 return app(environ, start_response) | 210 return app(environ, start_response) |
210 except Exception: | 211 except Exception: |
211 log.error(traceback.format_exc()) | 212 log.error(traceback.format_exc()) |
212 return HTTPInternalServerError()(environ, start_response) | 213 return HTTPInternalServerError()(environ, start_response) |
213 | 214 |
214 def __make_app(self, repo_name, repo_path): | 215 def __make_app(self, repo_name, repo_path, username): |
215 """ | 216 """ |
216 Make an wsgi application using dulserver | 217 Make an wsgi application using dulserver |
217 | 218 |
218 :param repo_name: name of the repository | 219 :param repo_name: name of the repository |
219 :param repo_path: full path to the repository | 220 :param repo_path: full path to the repository |
221 | 222 |
222 from rhodecode.lib.middleware.pygrack import make_wsgi_app | 223 from rhodecode.lib.middleware.pygrack import make_wsgi_app |
223 app = make_wsgi_app( | 224 app = make_wsgi_app( |
224 repo_root=os.path.dirname(repo_path), | 225 repo_root=os.path.dirname(repo_path), |
225 repo_name=repo_name, | 226 repo_name=repo_name, |
227 username=username, | |
226 ) | 228 ) |
227 return app | 229 return app |
228 | 230 |
229 def __get_repository(self, environ): | 231 def __get_repository(self, environ): |
230 """ | 232 """ |
266 # operation is pull/push | 268 # operation is pull/push |
267 op = getattr(self, '_git_stored_op', 'pull') | 269 op = getattr(self, '_git_stored_op', 'pull') |
268 return op | 270 return op |
269 | 271 |
270 def _handle_githooks(self, repo_name, action, baseui, environ): | 272 def _handle_githooks(self, repo_name, action, baseui, environ): |
271 from rhodecode.lib.hooks import log_pull_action, log_push_action | 273 """ |
274 Handles pull action, push is handled by pre-receive hook | |
275 """ | |
276 from rhodecode.lib.hooks import log_pull_action | |
272 service = environ['QUERY_STRING'].split('=') | 277 service = environ['QUERY_STRING'].split('=') |
273 if len(service) < 2: | 278 if len(service) < 2: |
274 return | 279 return |
275 | 280 |
276 from rhodecode.model.db import Repository | 281 from rhodecode.model.db import Repository |
277 _repo = Repository.get_by_repo_name(repo_name) | 282 _repo = Repository.get_by_repo_name(repo_name) |
278 _repo = _repo.scm_instance | 283 _repo = _repo.scm_instance |
279 _repo._repo.ui = baseui | 284 _repo._repo.ui = baseui |
280 | 285 |
281 push_hook = 'pretxnchangegroup.push_logger' | |
282 pull_hook = 'preoutgoing.pull_logger' | |
283 _hooks = dict(baseui.configitems('hooks')) or {} | 286 _hooks = dict(baseui.configitems('hooks')) or {} |
284 if action == 'push' and _hooks.get(push_hook): | 287 if action == 'pull' and _hooks.get(RhodeCodeUi.HOOK_PULL): |
285 log_push_action(ui=baseui, repo=_repo._repo) | |
286 elif action == 'pull' and _hooks.get(pull_hook): | |
287 log_pull_action(ui=baseui, repo=_repo._repo) | 288 log_pull_action(ui=baseui, repo=_repo._repo) |
288 | 289 |
289 def __inject_extras(self, repo_path, baseui, extras={}): | 290 def __inject_extras(self, repo_path, baseui, extras={}): |
290 """ | 291 """ |
291 Injects some extra params into baseui instance | 292 Injects some extra params into baseui instance |