diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2022-08-10 09:11:40 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2022-08-10 09:11:40 +0000 |
commit | ae1c8db2c805a6d3fad3a66fa31bd414cc071490 (patch) | |
tree | 2f5220cb19c64b46444e601db80ae46d5b3a2647 /app/workers/merge_requests | |
parent | f626c314923e5d4947531eab001929741c6bced1 (diff) | |
download | gitlab-ce-ae1c8db2c805a6d3fad3a66fa31bd414cc071490.tar.gz |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'app/workers/merge_requests')
3 files changed, 101 insertions, 0 deletions
diff --git a/app/workers/merge_requests/create_approval_note_worker.rb b/app/workers/merge_requests/create_approval_note_worker.rb new file mode 100644 index 00000000000..841431f6a9d --- /dev/null +++ b/app/workers/merge_requests/create_approval_note_worker.rb @@ -0,0 +1,32 @@ +# frozen_string_literal: true + +module MergeRequests + class CreateApprovalNoteWorker + include Gitlab::EventStore::Subscriber + + data_consistency :always + feature_category :code_review + urgency :low + idempotent! + + def handle_event(event) + current_user_id = event.data[:current_user_id] + merge_request_id = event.data[:merge_request_id] + current_user = User.find_by_id(current_user_id) + + unless current_user + logger.info(structured_payload(message: 'Current user not found.', current_user_id: current_user_id)) + return + end + + merge_request = MergeRequest.find_by_id(merge_request_id) + + unless merge_request + logger.info(structured_payload(message: 'Merge request not found.', merge_request_id: merge_request_id)) + return + end + + SystemNoteService.approve_mr(merge_request, current_user) + end + end +end diff --git a/app/workers/merge_requests/execute_approval_hooks_worker.rb b/app/workers/merge_requests/execute_approval_hooks_worker.rb new file mode 100644 index 00000000000..81eca425a38 --- /dev/null +++ b/app/workers/merge_requests/execute_approval_hooks_worker.rb @@ -0,0 +1,37 @@ +# frozen_string_literal: true + +module MergeRequests + class ExecuteApprovalHooksWorker + include Gitlab::EventStore::Subscriber + + data_consistency :always + feature_category :code_review + urgency :low + idempotent! + + # MergeRequests::ExecuteApprovalHooksService execute webhooks which are treated as external dependencies + worker_has_external_dependencies! + + def handle_event(event) + current_user_id = event.data[:current_user_id] + merge_request_id = event.data[:merge_request_id] + current_user = User.find_by_id(current_user_id) + + unless current_user + logger.info(structured_payload(message: 'Current user not found.', current_user_id: current_user_id)) + return + end + + merge_request = MergeRequest.find_by_id(merge_request_id) + + unless merge_request + logger.info(structured_payload(message: 'Merge request not found.', merge_request_id: merge_request_id)) + return + end + + ::MergeRequests::ExecuteApprovalHooksService + .new(project: merge_request.project, current_user: current_user) + .execute(merge_request) + end + end +end diff --git a/app/workers/merge_requests/resolve_todos_after_approval_worker.rb b/app/workers/merge_requests/resolve_todos_after_approval_worker.rb new file mode 100644 index 00000000000..7d9c76ea872 --- /dev/null +++ b/app/workers/merge_requests/resolve_todos_after_approval_worker.rb @@ -0,0 +1,32 @@ +# frozen_string_literal: true + +module MergeRequests + class ResolveTodosAfterApprovalWorker + include Gitlab::EventStore::Subscriber + + data_consistency :always + feature_category :code_review + urgency :low + idempotent! + + def handle_event(event) + current_user_id = event.data[:current_user_id] + merge_request_id = event.data[:merge_request_id] + current_user = User.find_by_id(current_user_id) + + unless current_user + logger.info(structured_payload(message: 'Current user not found.', current_user_id: current_user_id)) + return + end + + merge_request = MergeRequest.find_by_id(merge_request_id) + + unless merge_request + logger.info(structured_payload(message: 'Merge request not found.', merge_request_id: merge_request_id)) + return + end + + TodoService.new.resolve_todos_for_target(merge_request, current_user) + end + end +end |