##// END OF EJS Templates
webinterface file commiting executes push hooks ref #594
marcink -
r3478:796738bb beta
parent child Browse files
Show More
@@ -207,15 +207,17 b' def log_push_action(ui, repo, **kwargs):'
207 repository = extras['repository']
207 repository = extras['repository']
208 scm = extras['scm']
208 scm = extras['scm']
209 make_lock = extras['make_lock']
209 make_lock = extras['make_lock']
210 action = extras['action']
210 elif 'username' in rc_extras:
211 elif 'username' in rc_extras:
211 username = rc_extras['username']
212 username = rc_extras['username']
212 repository = rc_extras['repository']
213 repository = rc_extras['repository']
213 scm = rc_extras['scm']
214 scm = rc_extras['scm']
214 make_lock = rc_extras['make_lock']
215 make_lock = rc_extras['make_lock']
216 action = extras['action']
215 else:
217 else:
216 raise Exception('Missing data in repo.ui and os.environ')
218 raise Exception('Missing data in repo.ui and os.environ')
217
219
218 action = 'push' + ':%s'
220 action = action + ':%s'
219
221
220 if scm == 'hg':
222 if scm == 'hg':
221 node = kwargs['node']
223 node = kwargs['node']
@@ -44,13 +44,14 b' from rhodecode.lib.vcs.backends.base imp'
44
44
45 from rhodecode import BACKENDS
45 from rhodecode import BACKENDS
46 from rhodecode.lib import helpers as h
46 from rhodecode.lib import helpers as h
47 from rhodecode.lib.utils2 import safe_str, safe_unicode
47 from rhodecode.lib.utils2 import safe_str, safe_unicode, get_server_url
48 from rhodecode.lib.auth import HasRepoPermissionAny, HasReposGroupPermissionAny
48 from rhodecode.lib.auth import HasRepoPermissionAny, HasReposGroupPermissionAny
49 from rhodecode.lib.utils import get_filesystem_repos, make_ui, \
49 from rhodecode.lib.utils import get_filesystem_repos, make_ui, \
50 action_logger, REMOVED_REPO_PAT
50 action_logger, REMOVED_REPO_PAT
51 from rhodecode.model import BaseModel
51 from rhodecode.model import BaseModel
52 from rhodecode.model.db import Repository, RhodeCodeUi, CacheInvalidation, \
52 from rhodecode.model.db import Repository, RhodeCodeUi, CacheInvalidation, \
53 UserFollowing, UserLog, User, RepoGroup, PullRequest
53 UserFollowing, UserLog, User, RepoGroup, PullRequest
54 from rhodecode.lib.hooks import log_push_action
54
55
55 log = logging.getLogger(__name__)
56 log = logging.getLogger(__name__)
56
57
@@ -402,6 +403,31 b' class ScmModel(BaseModel):'
402 self.sa.add(repo)
403 self.sa.add(repo)
403 return repo
404 return repo
404
405
406 def _handle_push(self, repo, username, action, repo_name, repo_scm, revisions):
407 from rhodecode import CONFIG
408 from rhodecode.lib.base import _get_ip_addr
409 from pylons import request
410 environ = request.environ
411
412 #trigger push hook
413 extras = {
414 'ip': _get_ip_addr(environ),
415 'username': username,
416 'action': 'push_local',
417 'repository': repo_name,
418 'scm': repo_scm,
419 'config': CONFIG['__file__'],
420 'server_url': get_server_url(environ),
421 'make_lock': None,
422 'locked_by': [None, None]
423 }
424 _scm_repo = repo._repo
425 repo.inject_ui(**extras)
426 if repo_scm == 'hg':
427 log_push_action(_scm_repo.ui, _scm_repo, node=revisions[0])
428 elif repo_scm == 'git':
429 log_push_action(_scm_repo.ui, _scm_repo, _git_revs=revisions)
430
405 def pull_changes(self, repo, username):
431 def pull_changes(self, repo, username):
406 dbrepo = self.__get_repo(repo)
432 dbrepo = self.__get_repo(repo)
407 clone_uri = dbrepo.clone_uri
433 clone_uri = dbrepo.clone_uri
@@ -409,26 +435,13 b' class ScmModel(BaseModel):'
409 raise Exception("This repository doesn't have a clone uri")
435 raise Exception("This repository doesn't have a clone uri")
410
436
411 repo = dbrepo.scm_instance
437 repo = dbrepo.scm_instance
412 from rhodecode import CONFIG
438 repo_name = dbrepo.repo_name
413 try:
439 try:
414 extras = {
415 'ip': '',
416 'username': username,
417 'action': 'push_remote',
418 'repository': dbrepo.repo_name,
419 'scm': repo.alias,
420 'config': CONFIG['__file__'],
421 'make_lock': None,
422 'locked_by': [None, None]
423 }
424
425 Repository.inject_ui(repo, extras=extras)
426
427 if repo.alias == 'git':
440 if repo.alias == 'git':
428 repo.fetch(clone_uri)
441 repo.fetch(clone_uri)
429 else:
442 else:
430 repo.pull(clone_uri)
443 repo.pull(clone_uri)
431 self.mark_for_invalidation(dbrepo.repo_name)
444 self.mark_for_invalidation(repo_name)
432 except:
445 except:
433 log.error(traceback.format_exc())
446 log.error(traceback.format_exc())
434 raise
447 raise
@@ -441,7 +454,6 b' class ScmModel(BaseModel):'
441 :param repo: SCM instance
454 :param repo: SCM instance
442
455
443 """
456 """
444
445 if repo.alias == 'hg':
457 if repo.alias == 'hg':
446 from rhodecode.lib.vcs.backends.hg import \
458 from rhodecode.lib.vcs.backends.hg import \
447 MercurialInMemoryChangeset as IMC
459 MercurialInMemoryChangeset as IMC
@@ -463,9 +475,13 b' class ScmModel(BaseModel):'
463 author=author,
475 author=author,
464 parents=[cs], branch=cs.branch)
476 parents=[cs], branch=cs.branch)
465
477
466 action = 'push_local:%s' % tip.raw_id
467 action_logger(user, action, repo_name)
468 self.mark_for_invalidation(repo_name)
478 self.mark_for_invalidation(repo_name)
479 self._handle_push(repo,
480 username=user.username,
481 action='push_local',
482 repo_name=repo_name,
483 repo_scm=repo.alias,
484 revisions=[tip.raw_id])
469 return tip
485 return tip
470
486
471 def create_node(self, repo, repo_name, cs, user, author, message, content,
487 def create_node(self, repo, repo_name, cs, user, author, message, content,
@@ -502,9 +518,13 b' class ScmModel(BaseModel):'
502 author=author,
518 author=author,
503 parents=parents, branch=cs.branch)
519 parents=parents, branch=cs.branch)
504
520
505 action = 'push_local:%s' % tip.raw_id
506 action_logger(user, action, repo_name)
507 self.mark_for_invalidation(repo_name)
521 self.mark_for_invalidation(repo_name)
522 self._handle_push(repo,
523 username=user.username,
524 action='push_local',
525 repo_name=repo_name,
526 repo_scm=repo.alias,
527 revisions=[tip.raw_id])
508 return tip
528 return tip
509
529
510 def get_nodes(self, repo_name, revision, root_path='/', flat=True):
530 def get_nodes(self, repo_name, revision, root_path='/', flat=True):
General Comments 0
You need to be logged in to leave comments. Login now