##// END OF EJS Templates
chore(config): optimized celery configuration
chore(config): optimized celery configuration

File last commit:

r5095:aa627a5f default
r5299:2823fa9f default
Show More
hooks_utils.py
262 lines | 9.6 KiB | text/x-python | PythonLexer
copyrights: updated for 2023
r5088 # Copyright (C) 2010-2023 RhodeCode GmbH
project: added all source files and assets
r1 #
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License, version 3
# (only), as published by the Free Software Foundation.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
# This program is dual-licensed. If you wish to learn more about the
# RhodeCode Enterprise Edition, including its added features, Support services,
# and proprietary license terms, please see https://rhodecode.com/licenses/
import webob
pylons: remove pylons as dependency...
r2351 from pyramid.threadlocal import get_current_request
project: added all source files and assets
r1
dan
events: add pull request events
r378 from rhodecode import events
project: added all source files and assets
r1 from rhodecode.lib import hooks_base
from rhodecode.lib import utils2
dan
hooks: added new hooks for comments on pull requests and commits....
r4305 def _supports_repo_type(repo_type):
if repo_type in ('hg', 'git'):
return True
return False
def _get_vcs_operation_context(username, repo_name, repo_type, action):
# NOTE(dan): import loop
project: added all source files and assets
r1 from rhodecode.lib.base import vcs_operation_context
dan
hooks: added new hooks for comments on pull requests and commits....
r4305
project: added all source files and assets
r1 check_locking = action in ('pull', 'push')
pylons: remove pylons as dependency...
r2351 request = get_current_request()
project: added all source files and assets
r1 try:
dan
hooks: added new hooks for comments on pull requests and commits....
r4305 environ = request.environ
project: added all source files and assets
r1 except TypeError:
pylons: remove pylons as dependency...
r2351 # we might use this outside of request context
dan
hooks: added new hooks for comments on pull requests and commits....
r4305 environ = {}
project: added all source files and assets
r1
dan
hooks: added new hooks for comments on pull requests and commits....
r4305 if not environ:
environ = webob.Request.blank('').environ
extras = vcs_operation_context(environ, repo_name, username, action, repo_type, check_locking)
project: added all source files and assets
r1 return utils2.AttributeDict(extras)
dan
hooks: added new hooks for comments on pull requests and commits....
r4305 def trigger_post_push_hook(username, action, hook_type, repo_name, repo_type, commit_ids):
project: added all source files and assets
r1 """
Triggers push action hooks
:param username: username who pushes
:param action: push/push_local/push_remote
dan
hooks: added new hooks for comments on pull requests and commits....
r4305 :param hook_type: type of hook executed
project: added all source files and assets
r1 :param repo_name: name of repo
dan
hooks: added new hooks for comments on pull requests and commits....
r4305 :param repo_type: the type of SCM repo
project: added all source files and assets
r1 :param commit_ids: list of commit ids that we pushed
"""
dan
hooks: added new hooks for comments on pull requests and commits....
r4305 extras = _get_vcs_operation_context(username, repo_name, repo_type, action)
project: added all source files and assets
r1 extras.commit_ids = commit_ids
rcextensions: new builtin rcextensions....
r3133 extras.hook_type = hook_type
project: added all source files and assets
r1 hooks_base.post_push(extras)
dan
hooks: added new hooks for comments on pull requests and commits....
r4305 def trigger_comment_commit_hooks(username, repo_name, repo_type, repo, data=None):
"""
Triggers when a comment is made on a commit
:param username: username who creates the comment
:param repo_name: name of target repo
:param repo_type: the type of SCM target repo
:param repo: the repo object we trigger the event for
:param data: extra data for specific events e.g {'comment': comment_obj, 'commit': commit_obj}
"""
if not _supports_repo_type(repo_type):
return
extras = _get_vcs_operation_context(username, repo_name, repo_type, 'comment_commit')
comment = data['comment']
commit = data['commit']
events.trigger(events.RepoCommitCommentEvent(repo, commit, comment))
extras.update(repo.get_dict())
extras.commit = commit.serialize()
extras.comment = comment.get_api_data()
extras.created_by = username
comments: added rcextensions hoooks for comment editing, and renamed methods to remove odd log_ prefix which...
r4445 hooks_base.comment_commit_repository(**extras)
dan
hooks: added new hooks for comments on pull requests and commits....
r4305
comments: added new events for comment editing to handle them in integrations.
r4444 def trigger_comment_commit_edit_hooks(username, repo_name, repo_type, repo, data=None):
"""
Triggers when a comment is edited on a commit
:param username: username who edits the comment
:param repo_name: name of target repo
:param repo_type: the type of SCM target repo
:param repo: the repo object we trigger the event for
:param data: extra data for specific events e.g {'comment': comment_obj, 'commit': commit_obj}
"""
if not _supports_repo_type(repo_type):
return
extras = _get_vcs_operation_context(username, repo_name, repo_type, 'comment_commit')
comment = data['comment']
commit = data['commit']
events.trigger(events.RepoCommitCommentEditEvent(repo, commit, comment))
extras.update(repo.get_dict())
extras.commit = commit.serialize()
extras.comment = comment.get_api_data()
extras.created_by = username
comments: added rcextensions hoooks for comment editing, and renamed methods to remove odd log_ prefix which...
r4445 hooks_base.comment_edit_commit_repository(**extras)
comments: added new events for comment editing to handle them in integrations.
r4444
dan
hooks: added new hooks for comments on pull requests and commits....
r4305 def trigger_create_pull_request_hook(username, repo_name, repo_type, pull_request, data=None):
project: added all source files and assets
r1 """
Triggers create pull request action hooks
:param username: username who creates the pull request
:param repo_name: name of target repo
dan
hooks: added new hooks for comments on pull requests and commits....
r4305 :param repo_type: the type of SCM target repo
project: added all source files and assets
r1 :param pull_request: the pull request that was created
events: trigger 'review_status_change' when reviewers are updated....
r3415 :param data: extra data for specific events e.g {'comment': comment_obj}
project: added all source files and assets
r1 """
dan
hooks: added new hooks for comments on pull requests and commits....
r4305 if not _supports_repo_type(repo_type):
project: added all source files and assets
r1 return
dan
hooks: added new hooks for comments on pull requests and commits....
r4305 extras = _get_vcs_operation_context(username, repo_name, repo_type, 'create_pull_request')
dan
events: add pull request events
r378 events.trigger(events.PullRequestCreateEvent(pull_request))
pull-requests: updated metadata information for failed merges with multiple heads.
r3627 extras.update(pull_request.get_api_data(with_merge_state=False))
comments: added rcextensions hoooks for comment editing, and renamed methods to remove odd log_ prefix which...
r4445 hooks_base.create_pull_request(**extras)
project: added all source files and assets
r1
dan
hooks: added new hooks for comments on pull requests and commits....
r4305 def trigger_merge_pull_request_hook(username, repo_name, repo_type, pull_request, data=None):
project: added all source files and assets
r1 """
Triggers merge pull request action hooks
:param username: username who creates the pull request
:param repo_name: name of target repo
dan
hooks: added new hooks for comments on pull requests and commits....
r4305 :param repo_type: the type of SCM target repo
project: added all source files and assets
r1 :param pull_request: the pull request that was merged
events: trigger 'review_status_change' when reviewers are updated....
r3415 :param data: extra data for specific events e.g {'comment': comment_obj}
project: added all source files and assets
r1 """
dan
hooks: added new hooks for comments on pull requests and commits....
r4305 if not _supports_repo_type(repo_type):
project: added all source files and assets
r1 return
dan
hooks: added new hooks for comments on pull requests and commits....
r4305 extras = _get_vcs_operation_context(username, repo_name, repo_type, 'merge_pull_request')
dan
events: add pull request events
r378 events.trigger(events.PullRequestMergeEvent(pull_request))
project: added all source files and assets
r1 extras.update(pull_request.get_api_data())
comments: added rcextensions hoooks for comment editing, and renamed methods to remove odd log_ prefix which...
r4445 hooks_base.merge_pull_request(**extras)
project: added all source files and assets
r1
dan
hooks: added new hooks for comments on pull requests and commits....
r4305 def trigger_close_pull_request_hook(username, repo_name, repo_type, pull_request, data=None):
project: added all source files and assets
r1 """
Triggers close pull request action hooks
:param username: username who creates the pull request
:param repo_name: name of target repo
dan
hooks: added new hooks for comments on pull requests and commits....
r4305 :param repo_type: the type of SCM target repo
project: added all source files and assets
r1 :param pull_request: the pull request that was closed
events: trigger 'review_status_change' when reviewers are updated....
r3415 :param data: extra data for specific events e.g {'comment': comment_obj}
project: added all source files and assets
r1 """
dan
hooks: added new hooks for comments on pull requests and commits....
r4305 if not _supports_repo_type(repo_type):
project: added all source files and assets
r1 return
dan
hooks: added new hooks for comments on pull requests and commits....
r4305 extras = _get_vcs_operation_context(username, repo_name, repo_type, 'close_pull_request')
dan
events: add pull request events
r378 events.trigger(events.PullRequestCloseEvent(pull_request))
project: added all source files and assets
r1 extras.update(pull_request.get_api_data())
comments: added rcextensions hoooks for comment editing, and renamed methods to remove odd log_ prefix which...
r4445 hooks_base.close_pull_request(**extras)
project: added all source files and assets
r1
dan
hooks: added new hooks for comments on pull requests and commits....
r4305 def trigger_review_pull_request_hook(username, repo_name, repo_type, pull_request, data=None):
project: added all source files and assets
r1 """
Triggers review status change pull request action hooks
:param username: username who creates the pull request
:param repo_name: name of target repo
dan
hooks: added new hooks for comments on pull requests and commits....
r4305 :param repo_type: the type of SCM target repo
project: added all source files and assets
r1 :param pull_request: the pull request that review status changed
events: trigger 'review_status_change' when reviewers are updated....
r3415 :param data: extra data for specific events e.g {'comment': comment_obj}
project: added all source files and assets
r1 """
dan
hooks: added new hooks for comments on pull requests and commits....
r4305 if not _supports_repo_type(repo_type):
project: added all source files and assets
r1 return
dan
hooks: added new hooks for comments on pull requests and commits....
r4305 extras = _get_vcs_operation_context(username, repo_name, repo_type, 'review_pull_request')
events: trigger 'review_status_change' when reviewers are updated....
r3415 status = data.get('status')
events.trigger(events.PullRequestReviewEvent(pull_request, status))
project: added all source files and assets
r1 extras.update(pull_request.get_api_data())
comments: added rcextensions hoooks for comment editing, and renamed methods to remove odd log_ prefix which...
r4445 hooks_base.review_pull_request(**extras)
project: added all source files and assets
r1
dan
hooks: added new hooks for comments on pull requests and commits....
r4305 def trigger_comment_pull_request_hook(username, repo_name, repo_type, pull_request, data=None):
"""
Triggers when a comment is made on a pull request
:param username: username who creates the pull request
:param repo_name: name of target repo
:param repo_type: the type of SCM target repo
:param pull_request: the pull request that comment was made on
:param data: extra data for specific events e.g {'comment': comment_obj}
"""
if not _supports_repo_type(repo_type):
return
extras = _get_vcs_operation_context(username, repo_name, repo_type, 'comment_pull_request')
comment = data['comment']
events.trigger(events.PullRequestCommentEvent(pull_request, comment))
extras.update(pull_request.get_api_data())
extras.comment = comment.get_api_data()
comments: added rcextensions hoooks for comment editing, and renamed methods to remove odd log_ prefix which...
r4445 hooks_base.comment_pull_request(**extras)
dan
hooks: added new hooks for comments on pull requests and commits....
r4305
comments: added new events for comment editing to handle them in integrations.
r4444 def trigger_comment_pull_request_edit_hook(username, repo_name, repo_type, pull_request, data=None):
"""
Triggers when a comment was edited on a pull request
:param username: username who made the edit
:param repo_name: name of target repo
:param repo_type: the type of SCM target repo
:param pull_request: the pull request that comment was made on
:param data: extra data for specific events e.g {'comment': comment_obj}
"""
if not _supports_repo_type(repo_type):
return
extras = _get_vcs_operation_context(username, repo_name, repo_type, 'comment_pull_request')
comment = data['comment']
events.trigger(events.PullRequestCommentEditEvent(pull_request, comment))
extras.update(pull_request.get_api_data())
extras.comment = comment.get_api_data()
comments: added rcextensions hoooks for comment editing, and renamed methods to remove odd log_ prefix which...
r4445 hooks_base.comment_edit_pull_request(**extras)
comments: added new events for comment editing to handle them in integrations.
r4444
dan
hooks: added new hooks for comments on pull requests and commits....
r4305 def trigger_update_pull_request_hook(username, repo_name, repo_type, pull_request, data=None):
project: added all source files and assets
r1 """
Triggers update pull request action hooks
:param username: username who creates the pull request
:param repo_name: name of target repo
dan
hooks: added new hooks for comments on pull requests and commits....
r4305 :param repo_type: the type of SCM target repo
project: added all source files and assets
r1 :param pull_request: the pull request that was updated
events: trigger 'review_status_change' when reviewers are updated....
r3415 :param data: extra data for specific events e.g {'comment': comment_obj}
project: added all source files and assets
r1 """
dan
hooks: added new hooks for comments on pull requests and commits....
r4305 if not _supports_repo_type(repo_type):
project: added all source files and assets
r1 return
dan
hooks: added new hooks for comments on pull requests and commits....
r4305 extras = _get_vcs_operation_context(username, repo_name, repo_type, 'update_pull_request')
dan
events: add pull request events
r378 events.trigger(events.PullRequestUpdateEvent(pull_request))
project: added all source files and assets
r1 extras.update(pull_request.get_api_data())
comments: added rcextensions hoooks for comment editing, and renamed methods to remove odd log_ prefix which...
r4445 hooks_base.update_pull_request(**extras)