# HG changeset patch # User Marcin Kuzminski # Date 2020-07-14 09:24:40 # Node ID 5a5c90c04f6e9b5711f3c82c562a969af3d696d6 # Parent 912182ba879faa1ed72ba1b96be555b2510c5217 comments: added rcextensions hoooks for comment editing, and renamed methods to remove odd log_ prefix which isn't exactly what those functions were actually doing. diff --git a/rhodecode/config/rcextensions/__init__.py b/rhodecode/config/rcextensions/__init__.py --- a/rhodecode/config/rcextensions/__init__.py +++ b/rhodecode/config/rcextensions/__init__.py @@ -26,6 +26,7 @@ from .hooks import ( _pre_create_user_hook, _create_user_hook, _comment_commit_repo_hook, + _comment_edit_commit_repo_hook, _delete_repo_hook, _delete_user_hook, _pre_push_hook, @@ -35,6 +36,7 @@ from .hooks import ( _create_pull_request_hook, _review_pull_request_hook, _comment_pull_request_hook, + _comment_edit_pull_request_hook, _update_pull_request_hook, _merge_pull_request_hook, _close_pull_request_hook, @@ -43,6 +45,7 @@ from .hooks import ( # set as module attributes, we use those to call hooks. *do not change this* CREATE_REPO_HOOK = _create_repo_hook COMMENT_COMMIT_REPO_HOOK = _comment_commit_repo_hook +COMMENT_EDIT_COMMIT_REPO_HOOK = _comment_edit_commit_repo_hook CREATE_REPO_GROUP_HOOK = _create_repo_group_hook PRE_CREATE_USER_HOOK = _pre_create_user_hook CREATE_USER_HOOK = _create_user_hook @@ -55,6 +58,7 @@ PULL_HOOK = _pull_hook CREATE_PULL_REQUEST = _create_pull_request_hook REVIEW_PULL_REQUEST = _review_pull_request_hook COMMENT_PULL_REQUEST = _comment_pull_request_hook +COMMENT_EDIT_PULL_REQUEST = _comment_edit_pull_request_hook UPDATE_PULL_REQUEST = _update_pull_request_hook MERGE_PULL_REQUEST = _merge_pull_request_hook CLOSE_PULL_REQUEST = _close_pull_request_hook diff --git a/rhodecode/config/rcextensions/hooks.py b/rhodecode/config/rcextensions/hooks.py --- a/rhodecode/config/rcextensions/hooks.py +++ b/rhodecode/config/rcextensions/hooks.py @@ -83,6 +83,33 @@ def _comment_commit_repo_hook(*args, **k @has_kwargs({ + 'repo_name': '', + 'repo_type': '', + 'description': '', + 'private': '', + 'created_on': '', + 'enable_downloads': '', + 'repo_id': '', + 'user_id': '', + 'enable_statistics': '', + 'clone_uri': '', + 'fork_id': '', + 'group_id': '', + 'created_by': '', + 'repository': '', + 'comment': '', + 'commit': '' +}) +def _comment_edit_commit_repo_hook(*args, **kwargs): + """ + POST CREATE REPOSITORY COMMENT ON COMMIT HOOK. This function will be executed after + a comment is made on this repository commit. + + """ + return HookResponse(0, '') + + +@has_kwargs({ 'group_name': '', 'group_parent_id': '', 'group_description': '', @@ -408,6 +435,38 @@ def _comment_pull_request_hook(*args, ** 'scm': 'type of version control "git", "hg", "svn"', 'username': 'username of actor who triggered this event', 'ip': 'ip address of actor who triggered this hook', + + 'action': '', + 'repository': 'repository name', + 'pull_request_id': '', + 'url': '', + 'title': '', + 'description': '', + 'status': '', + 'comment': '', + 'created_on': '', + 'updated_on': '', + 'commit_ids': '', + 'review_status': '', + 'mergeable': '', + 'source': '', + 'target': '', + 'author': '', + 'reviewers': '', +}) +def _comment_edit_pull_request_hook(*args, **kwargs): + """ + This hook will be executed after comment is made on a pull request + """ + return HookResponse(0, '') + + +@has_kwargs({ + 'server_url': 'url of instance that triggered this hook', + 'config': 'path to .ini config used', + 'scm': 'type of version control "git", "hg", "svn"', + 'username': 'username of actor who triggered this event', + 'ip': 'ip address of actor who triggered this hook', 'action': '', 'repository': 'repository name', 'pull_request_id': '', diff --git a/rhodecode/lib/celerylib/tasks.py b/rhodecode/lib/celerylib/tasks.py --- a/rhodecode/lib/celerylib/tasks.py +++ b/rhodecode/lib/celerylib/tasks.py @@ -33,7 +33,7 @@ from pyramid_mailer.message import Messa import rhodecode from rhodecode.lib import audit_logger from rhodecode.lib.celerylib import get_logger, async_task, RequestContextTask -from rhodecode.lib.hooks_base import log_create_repository +from rhodecode.lib import hooks_base from rhodecode.lib.utils2 import safe_int, str2bool from rhodecode.model.db import ( Session, IntegrityError, true, Repository, RepoGroup, User) @@ -187,7 +187,7 @@ def create_repo(form_data, cur_user): clone_uri=clone_uri, ) repo = Repository.get_by_repo_name(repo_name_full) - log_create_repository(created_by=owner.username, **repo.get_dict()) + hooks_base.create_repository(created_by=owner.username, **repo.get_dict()) # update repo commit caches initially repo.update_commit_cache() @@ -273,7 +273,7 @@ def create_repo_fork(form_data, cur_user clone_uri=source_repo_path, ) repo = Repository.get_by_repo_name(repo_name_full) - log_create_repository(created_by=owner.username, **repo.get_dict()) + hooks_base.create_repository(created_by=owner.username, **repo.get_dict()) # update repo commit caches initially config = repo._config diff --git a/rhodecode/lib/hooks_base.py b/rhodecode/lib/hooks_base.py --- a/rhodecode/lib/hooks_base.py +++ b/rhodecode/lib/hooks_base.py @@ -400,7 +400,7 @@ pre_create_user = ExtensionCallback( 'admin', 'created_by')) -log_create_pull_request = ExtensionCallback( +create_pull_request = ExtensionCallback( hook_name='CREATE_PULL_REQUEST', kwargs_keys=( 'server_url', 'config', 'scm', 'username', 'ip', 'action', @@ -409,7 +409,7 @@ log_create_pull_request = ExtensionCallb 'mergeable', 'source', 'target', 'author', 'reviewers')) -log_merge_pull_request = ExtensionCallback( +merge_pull_request = ExtensionCallback( hook_name='MERGE_PULL_REQUEST', kwargs_keys=( 'server_url', 'config', 'scm', 'username', 'ip', 'action', @@ -418,7 +418,7 @@ log_merge_pull_request = ExtensionCallba 'mergeable', 'source', 'target', 'author', 'reviewers')) -log_close_pull_request = ExtensionCallback( +close_pull_request = ExtensionCallback( hook_name='CLOSE_PULL_REQUEST', kwargs_keys=( 'server_url', 'config', 'scm', 'username', 'ip', 'action', @@ -427,7 +427,7 @@ log_close_pull_request = ExtensionCallba 'mergeable', 'source', 'target', 'author', 'reviewers')) -log_review_pull_request = ExtensionCallback( +review_pull_request = ExtensionCallback( hook_name='REVIEW_PULL_REQUEST', kwargs_keys=( 'server_url', 'config', 'scm', 'username', 'ip', 'action', @@ -436,7 +436,7 @@ log_review_pull_request = ExtensionCallb 'mergeable', 'source', 'target', 'author', 'reviewers')) -log_comment_pull_request = ExtensionCallback( +comment_pull_request = ExtensionCallback( hook_name='COMMENT_PULL_REQUEST', kwargs_keys=( 'server_url', 'config', 'scm', 'username', 'ip', 'action', @@ -445,7 +445,16 @@ log_comment_pull_request = ExtensionCall 'mergeable', 'source', 'target', 'author', 'reviewers')) -log_update_pull_request = ExtensionCallback( +comment_edit_pull_request = ExtensionCallback( + hook_name='COMMENT_EDIT_PULL_REQUEST', + kwargs_keys=( + 'server_url', 'config', 'scm', 'username', 'ip', 'action', + 'repository', 'pull_request_id', 'url', 'title', 'description', + 'status', 'comment', 'created_on', 'updated_on', 'commit_ids', 'review_status', + 'mergeable', 'source', 'target', 'author', 'reviewers')) + + +update_pull_request = ExtensionCallback( hook_name='UPDATE_PULL_REQUEST', kwargs_keys=( 'server_url', 'config', 'scm', 'username', 'ip', 'action', @@ -454,7 +463,7 @@ log_update_pull_request = ExtensionCallb 'mergeable', 'source', 'target', 'author', 'reviewers')) -log_create_user = ExtensionCallback( +create_user = ExtensionCallback( hook_name='CREATE_USER_HOOK', kwargs_keys=( 'username', 'full_name_or_username', 'full_contact', 'user_id', @@ -465,7 +474,7 @@ log_create_user = ExtensionCallback( 'inherit_default_permissions', 'created_by', 'created_on')) -log_delete_user = ExtensionCallback( +delete_user = ExtensionCallback( hook_name='DELETE_USER_HOOK', kwargs_keys=( 'username', 'full_name_or_username', 'full_contact', 'user_id', @@ -476,7 +485,7 @@ log_delete_user = ExtensionCallback( 'inherit_default_permissions', 'deleted_by')) -log_create_repository = ExtensionCallback( +create_repository = ExtensionCallback( hook_name='CREATE_REPO_HOOK', kwargs_keys=( 'repo_name', 'repo_type', 'description', 'private', 'created_on', @@ -484,7 +493,7 @@ log_create_repository = ExtensionCallbac 'clone_uri', 'fork_id', 'group_id', 'created_by')) -log_delete_repository = ExtensionCallback( +delete_repository = ExtensionCallback( hook_name='DELETE_REPO_HOOK', kwargs_keys=( 'repo_name', 'repo_type', 'description', 'private', 'created_on', @@ -492,7 +501,7 @@ log_delete_repository = ExtensionCallbac 'clone_uri', 'fork_id', 'group_id', 'deleted_by', 'deleted_on')) -log_comment_commit_repository = ExtensionCallback( +comment_commit_repository = ExtensionCallback( hook_name='COMMENT_COMMIT_REPO_HOOK', kwargs_keys=( 'repo_name', 'repo_type', 'description', 'private', 'created_on', @@ -500,8 +509,16 @@ log_comment_commit_repository = Extensio 'clone_uri', 'fork_id', 'group_id', 'repository', 'created_by', 'comment', 'commit')) +comment_edit_commit_repository = ExtensionCallback( + hook_name='COMMENT_EDIT_COMMIT_REPO_HOOK', + kwargs_keys=( + 'repo_name', 'repo_type', 'description', 'private', 'created_on', + 'enable_downloads', 'repo_id', 'user_id', 'enable_statistics', + 'clone_uri', 'fork_id', 'group_id', + 'repository', 'created_by', 'comment', 'commit')) -log_create_repository_group = ExtensionCallback( + +create_repository_group = ExtensionCallback( hook_name='CREATE_REPO_GROUP_HOOK', kwargs_keys=( 'group_name', 'group_parent_id', 'group_description', diff --git a/rhodecode/lib/hooks_utils.py b/rhodecode/lib/hooks_utils.py --- a/rhodecode/lib/hooks_utils.py +++ b/rhodecode/lib/hooks_utils.py @@ -94,7 +94,7 @@ def trigger_comment_commit_hooks(usernam extras.commit = commit.serialize() extras.comment = comment.get_api_data() extras.created_by = username - hooks_base.log_comment_commit_repository(**extras) + hooks_base.comment_commit_repository(**extras) def trigger_comment_commit_edit_hooks(username, repo_name, repo_type, repo, data=None): @@ -121,8 +121,7 @@ def trigger_comment_commit_edit_hooks(us extras.commit = commit.serialize() extras.comment = comment.get_api_data() extras.created_by = username - # TODO(marcink): rcextensions handlers ?? - hooks_base.log_comment_commit_repository(**extras) + hooks_base.comment_edit_commit_repository(**extras) def trigger_create_pull_request_hook(username, repo_name, repo_type, pull_request, data=None): @@ -141,7 +140,7 @@ def trigger_create_pull_request_hook(use extras = _get_vcs_operation_context(username, repo_name, repo_type, 'create_pull_request') events.trigger(events.PullRequestCreateEvent(pull_request)) extras.update(pull_request.get_api_data(with_merge_state=False)) - hooks_base.log_create_pull_request(**extras) + hooks_base.create_pull_request(**extras) def trigger_merge_pull_request_hook(username, repo_name, repo_type, pull_request, data=None): @@ -160,7 +159,7 @@ def trigger_merge_pull_request_hook(user extras = _get_vcs_operation_context(username, repo_name, repo_type, 'merge_pull_request') events.trigger(events.PullRequestMergeEvent(pull_request)) extras.update(pull_request.get_api_data()) - hooks_base.log_merge_pull_request(**extras) + hooks_base.merge_pull_request(**extras) def trigger_close_pull_request_hook(username, repo_name, repo_type, pull_request, data=None): @@ -179,7 +178,7 @@ def trigger_close_pull_request_hook(user extras = _get_vcs_operation_context(username, repo_name, repo_type, 'close_pull_request') events.trigger(events.PullRequestCloseEvent(pull_request)) extras.update(pull_request.get_api_data()) - hooks_base.log_close_pull_request(**extras) + hooks_base.close_pull_request(**extras) def trigger_review_pull_request_hook(username, repo_name, repo_type, pull_request, data=None): @@ -199,7 +198,7 @@ def trigger_review_pull_request_hook(use status = data.get('status') events.trigger(events.PullRequestReviewEvent(pull_request, status)) extras.update(pull_request.get_api_data()) - hooks_base.log_review_pull_request(**extras) + hooks_base.review_pull_request(**extras) def trigger_comment_pull_request_hook(username, repo_name, repo_type, pull_request, data=None): @@ -221,7 +220,7 @@ def trigger_comment_pull_request_hook(us events.trigger(events.PullRequestCommentEvent(pull_request, comment)) extras.update(pull_request.get_api_data()) extras.comment = comment.get_api_data() - hooks_base.log_comment_pull_request(**extras) + hooks_base.comment_pull_request(**extras) def trigger_comment_pull_request_edit_hook(username, repo_name, repo_type, pull_request, data=None): @@ -243,8 +242,7 @@ def trigger_comment_pull_request_edit_ho events.trigger(events.PullRequestCommentEditEvent(pull_request, comment)) extras.update(pull_request.get_api_data()) extras.comment = comment.get_api_data() - # TODO(marcink): handle rcextensions... - hooks_base.log_comment_pull_request(**extras) + hooks_base.comment_edit_pull_request(**extras) def trigger_update_pull_request_hook(username, repo_name, repo_type, pull_request, data=None): @@ -263,4 +261,4 @@ def trigger_update_pull_request_hook(use extras = _get_vcs_operation_context(username, repo_name, repo_type, 'update_pull_request') events.trigger(events.PullRequestUpdateEvent(pull_request)) extras.update(pull_request.get_api_data()) - hooks_base.log_update_pull_request(**extras) + hooks_base.update_pull_request(**extras) diff --git a/rhodecode/model/repo.py b/rhodecode/model/repo.py --- a/rhodecode/model/repo.py +++ b/rhodecode/model/repo.py @@ -33,7 +33,7 @@ from rhodecode import events from rhodecode.lib.auth import HasUserGroupPermissionAny from rhodecode.lib.caching_query import FromCache from rhodecode.lib.exceptions import AttachedForksError, AttachedPullRequestsError -from rhodecode.lib.hooks_base import log_delete_repository +from rhodecode.lib import hooks_base from rhodecode.lib.user_log_filter import user_log_filter from rhodecode.lib.utils import make_db_config from rhodecode.lib.utils2 import ( @@ -767,7 +767,7 @@ class RepoModel(BaseModel): 'deleted_by': cur_user, 'deleted_on': time.time(), }) - log_delete_repository(**old_repo_dict) + hooks_base.delete_repository(**old_repo_dict) events.trigger(events.RepoDeleteEvent(repo)) except Exception: log.error(traceback.format_exc()) diff --git a/rhodecode/model/repo_group.py b/rhodecode/model/repo_group.py --- a/rhodecode/model/repo_group.py +++ b/rhodecode/model/repo_group.py @@ -308,13 +308,13 @@ class RepoGroupModel(BaseModel): self._create_group(new_repo_group.group_name) # trigger the post hook - from rhodecode.lib.hooks_base import log_create_repository_group + from rhodecode.lib import hooks_base repo_group = RepoGroup.get_by_group_name(group_name) # update repo group commit caches initially repo_group.update_commit_cache() - log_create_repository_group( + hooks_base.create_repository_group( created_by=user.username, **repo_group.get_dict()) # Trigger create event. diff --git a/rhodecode/model/user.py b/rhodecode/model/user.py --- a/rhodecode/model/user.py +++ b/rhodecode/model/user.py @@ -262,8 +262,7 @@ class UserModel(BaseModel): from rhodecode.lib.auth import ( get_crypt_password, check_password) - from rhodecode.lib.hooks_base import ( - log_create_user, check_allowed_create_user) + from rhodecode.lib import hooks_base def _password_change(new_user, password): old_password = new_user.password or '' @@ -327,7 +326,7 @@ class UserModel(BaseModel): if new_active_user and strict_creation_check: # raises UserCreationError if it's not allowed for any reason to # create new active user, this also executes pre-create hooks - check_allowed_create_user(user_data, cur_user, strict_check=True) + hooks_base.check_allowed_create_user(user_data, cur_user, strict_check=True) events.trigger(events.UserPreCreate(user_data)) new_user = User() edit = False @@ -390,7 +389,7 @@ class UserModel(BaseModel): kwargs = new_user.get_dict() # backward compat, require api_keys present kwargs['api_keys'] = kwargs['auth_tokens'] - log_create_user(created_by=cur_user, **kwargs) + hooks_base.create_user(created_by=cur_user, **kwargs) events.trigger(events.UserPostCreate(user_data)) return new_user except (DatabaseError,): @@ -569,7 +568,7 @@ class UserModel(BaseModel): def delete(self, user, cur_user=None, handle_repos=None, handle_repo_groups=None, handle_user_groups=None, handle_pull_requests=None, handle_artifacts=None, handle_new_owner=None): - from rhodecode.lib.hooks_base import log_delete_user + from rhodecode.lib import hooks_base if not cur_user: cur_user = getattr(get_current_rhodecode_user(), 'username', None) @@ -638,7 +637,7 @@ class UserModel(BaseModel): self.sa.expire(user) self.sa.delete(user) - log_delete_user(deleted_by=cur_user, **user_data) + hooks_base.delete_user(deleted_by=cur_user, **user_data) except Exception: log.error(traceback.format_exc()) raise