Mercurial > kallithea
changeset 8741:9b7c5d7ad1a2
hooks: import whole hooks module
Minimize impact if there should be cycles.
author | Mads Kiilerich <mads@kiilerich.com> |
---|---|
date | Mon, 02 Nov 2020 14:07:16 +0100 |
parents | 28b845dca1fd |
children | 94a21c71df91 |
files | kallithea/config/middleware/simplegit.py kallithea/lib/celerylib/tasks.py kallithea/lib/vcs/ssh/git.py kallithea/model/pull_request.py kallithea/model/repo.py kallithea/model/scm.py kallithea/model/user.py |
diffstat | 7 files changed, 19 insertions(+), 24 deletions(-) [+] |
line wrap: on
line diff
--- a/kallithea/config/middleware/simplegit.py Mon Nov 02 14:30:22 2020 +0100 +++ b/kallithea/config/middleware/simplegit.py Mon Nov 02 14:07:16 2020 +0100 @@ -32,8 +32,8 @@ import re from kallithea.config.middleware.pygrack import make_wsgi_app +from kallithea.lib import hooks from kallithea.lib.base import BaseVCSController, get_path_info -from kallithea.lib.hooks import log_pull_action from kallithea.lib.utils import make_ui from kallithea.model import db @@ -90,7 +90,7 @@ repo = db.Repository.get_by_repo_name(parsed_request.repo_name) scm_repo = repo.scm_instance # Run hooks, like Mercurial outgoing.pull_logger does - log_pull_action(ui=baseui, repo=scm_repo._repo) + hooks.log_pull_action(ui=baseui, repo=scm_repo._repo) # Note: push hooks are handled by post-receive hook return pygrack_app(environ, start_response)
--- a/kallithea/lib/celerylib/tasks.py Mon Nov 02 14:30:22 2020 +0100 +++ b/kallithea/lib/celerylib/tasks.py Mon Nov 02 14:07:16 2020 +0100 @@ -42,8 +42,7 @@ import kallithea import kallithea.lib.helpers as h -from kallithea.lib import celerylib, conf, ext_json -from kallithea.lib.hooks import log_create_repository +from kallithea.lib import celerylib, conf, ext_json, hooks from kallithea.lib.indexers.daemon import WhooshIndexingDaemon from kallithea.lib.utils import action_logger from kallithea.lib.utils2 import asbool, ascii_bytes @@ -407,7 +406,7 @@ clone_uri=clone_uri, ) repo = db.Repository.get_by_repo_name(repo_name_full) - log_create_repository(repo.get_dict(), created_by=owner.username) + hooks.log_create_repository(repo.get_dict(), created_by=owner.username) # update repo changeset caches initially repo.update_changeset_cache() @@ -483,7 +482,7 @@ clone_uri=source_repo_path, ) repo = db.Repository.get_by_repo_name(repo_name_full) - log_create_repository(repo.get_dict(), created_by=owner.username) + hooks.log_create_repository(repo.get_dict(), created_by=owner.username) # update repo changeset caches initially repo.update_changeset_cache()
--- a/kallithea/lib/vcs/ssh/git.py Mon Nov 02 14:30:22 2020 +0100 +++ b/kallithea/lib/vcs/ssh/git.py Mon Nov 02 14:07:16 2020 +0100 @@ -15,7 +15,7 @@ import logging import os -from kallithea.lib.hooks import log_pull_action +from kallithea.lib import hooks from kallithea.lib.utils import make_ui from kallithea.lib.vcs.ssh import base @@ -66,7 +66,7 @@ def _serve(self): if self.verb == 'git-upload-pack': # action 'pull' # base class called set_hook_environment - action is hardcoded to 'pull' - log_pull_action(ui=make_ui(), repo=self.db_repo.scm_instance._repo) + hooks.log_pull_action(ui=make_ui(), repo=self.db_repo.scm_instance._repo) else: # probably verb 'git-receive-pack', action 'push' if not self.allow_push: self.exit('Push access to %r denied' % self.repo_name)
--- a/kallithea/model/pull_request.py Mon Nov 02 14:30:22 2020 +0100 +++ b/kallithea/model/pull_request.py Mon Nov 02 14:07:16 2020 +0100 @@ -32,8 +32,7 @@ from tg import request from tg.i18n import ugettext as _ -from kallithea.lib import auth, webutils -from kallithea.lib.hooks import log_create_pullrequest +from kallithea.lib import auth, hooks, webutils from kallithea.lib.utils import extract_mentioned_users from kallithea.lib.utils2 import ascii_bytes, short_ref_name, shorter from kallithea.model import changeset_status, comment, db, meta, notification @@ -290,7 +289,7 @@ mention_recipients = extract_mentioned_users(self.description) PullRequestModel().add_reviewers(created_by, pr, self.reviewers, mention_recipients) - log_create_pullrequest(pr.get_dict(), created_by) + hooks.log_create_pullrequest(pr.get_dict(), created_by) return pr
--- a/kallithea/model/repo.py Mon Nov 02 14:30:22 2020 +0100 +++ b/kallithea/model/repo.py Mon Nov 02 14:07:16 2020 +0100 @@ -33,9 +33,9 @@ from datetime import datetime import kallithea.lib.utils2 +from kallithea.lib import hooks from kallithea.lib.auth import HasRepoPermissionLevel, HasUserGroupPermissionLevel from kallithea.lib.exceptions import AttachedForksError -from kallithea.lib.hooks import log_delete_repository from kallithea.lib.utils import is_valid_repo_uri, make_ui from kallithea.lib.utils2 import LazyProperty, get_current_authuser, obfuscate_url_pw, remove_prefix from kallithea.lib.vcs.backends import get_backend @@ -483,7 +483,7 @@ self._delete_filesystem_repo(repo) else: log.debug('skipping removal from filesystem') - log_delete_repository(old_repo_dict, + hooks.log_delete_repository(old_repo_dict, deleted_by=cur_user) except Exception: log.error(traceback.format_exc())
--- a/kallithea/model/scm.py Mon Nov 02 14:30:22 2020 +0100 +++ b/kallithea/model/scm.py Mon Nov 02 14:07:16 2020 +0100 @@ -37,9 +37,9 @@ from tg.i18n import ugettext as _ import kallithea +from kallithea.lib import hooks from kallithea.lib.auth import HasPermissionAny, HasRepoGroupPermissionLevel, HasRepoPermissionLevel, HasUserGroupPermissionLevel from kallithea.lib.exceptions import IMCCommitError, NonRelativePathError -from kallithea.lib.hooks import process_pushed_raw_ids from kallithea.lib.utils import action_logger, get_filesystem_repos, make_ui from kallithea.lib.utils2 import safe_bytes, safe_str, set_hook_environment, umask from kallithea.lib.vcs import get_repo @@ -328,7 +328,7 @@ :param revisions: list of revisions that we pushed """ set_hook_environment(username, ip_addr, repo_name, repo_alias=repo.alias, action=action) - process_pushed_raw_ids(revisions) # also calls mark_for_invalidation + hooks.process_pushed_raw_ids(revisions) # also calls mark_for_invalidation def pull_changes(self, repo, username, ip_addr, clone_uri=None): """
--- a/kallithea/model/user.py Mon Nov 02 14:30:22 2020 +0100 +++ b/kallithea/model/user.py Mon Nov 02 14:07:16 2020 +0100 @@ -36,7 +36,7 @@ from tg import config from tg.i18n import ugettext as _ -from kallithea.lib import webutils +from kallithea.lib import hooks, webutils from kallithea.lib.exceptions import DefaultUserException, UserOwnsReposException from kallithea.lib.utils2 import check_password, generate_api_key, get_crypt_password, get_current_authuser from kallithea.model import db, forms, meta @@ -59,7 +59,6 @@ if not cur_user: cur_user = getattr(get_current_authuser(), 'username', None) - from kallithea.lib.hooks import check_allowed_create_user, log_create_user _fd = form_data user_data = { 'username': _fd['username'], @@ -71,7 +70,7 @@ 'admin': False } # raises UserCreationError if it's not allowed - check_allowed_create_user(user_data, cur_user) + hooks.check_allowed_create_user(user_data, cur_user) new_user = db.User() for k, v in form_data.items(): @@ -85,7 +84,7 @@ meta.Session().add(new_user) meta.Session().flush() # make database assign new_user.user_id - log_create_user(new_user.get_dict(), cur_user) + hooks.log_create_user(new_user.get_dict(), cur_user) return new_user def create_or_update(self, username, password, email, firstname='', @@ -109,14 +108,13 @@ if not cur_user: cur_user = getattr(get_current_authuser(), 'username', None) - from kallithea.lib.hooks import check_allowed_create_user, log_create_user user_data = { 'username': username, 'password': password, 'email': email, 'firstname': firstname, 'lastname': lastname, 'active': active, 'admin': admin } # raises UserCreationError if it's not allowed - check_allowed_create_user(user_data, cur_user) + hooks.check_allowed_create_user(user_data, cur_user) log.debug('Checking for %s account in Kallithea database', username) user = db.User.get_by_username(username, case_insensitive=True) @@ -156,7 +154,7 @@ meta.Session().flush() # make database assign new_user.user_id if not edit: - log_create_user(new_user.get_dict(), cur_user) + hooks.log_create_user(new_user.get_dict(), cur_user) return new_user except (DatabaseError,): @@ -255,8 +253,7 @@ % (user.username, len(usergroups), ', '.join(usergroups))) meta.Session().delete(user) - from kallithea.lib.hooks import log_delete_user - log_delete_user(user.get_dict(), cur_user) + hooks.log_delete_user(user.get_dict(), cur_user) def can_change_password(self, user): from kallithea.lib import auth_modules