Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2023-06-14 00:09:09 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2023-06-14 00:09:09 +0300
commit04cc87ee46c1c0b6b4eb7df964b3115dd2578877 (patch)
tree2c64b0e21804fc0981a2142eb83a0b73d85fbcda /app/services
parent4a064b8dc0bf350b1b3000698042b49113e758d1 (diff)
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'app/services')
-rw-r--r--app/services/notes/create_service.rb27
-rw-r--r--app/services/notes/quick_actions_service.rb16
2 files changed, 32 insertions, 11 deletions
diff --git a/app/services/notes/create_service.rb b/app/services/notes/create_service.rb
index 968d0414392..fdab2a07990 100644
--- a/app/services/notes/create_service.rb
+++ b/app/services/notes/create_service.rb
@@ -107,16 +107,10 @@ module Notes
def do_commands(note, update_params, message, command_names, only_commands)
return if quick_actions_service.commands_executed_count.to_i == 0
- if update_params.present?
- invalid_message = validate_commands(note, update_params)
-
- if invalid_message
- note.errors.add(:validation, invalid_message)
- message = invalid_message
- else
- quick_actions_service.apply_updates(update_params, note)
- note.commands_changes = update_params
- end
+ update_error = quick_actions_update_errors(note, update_params)
+ if update_error
+ note.errors.add(:validation, update_error)
+ message = update_error
end
# We must add the error after we call #save because errors are reset
@@ -129,6 +123,19 @@ module Notes
end
end
+ def quick_actions_update_errors(note, params)
+ return unless params.present?
+
+ invalid_message = validate_commands(note, params)
+ return invalid_message if invalid_message
+
+ service_response = quick_actions_service.apply_updates(params, note)
+ note.commands_changes = params
+ return if service_response.success?
+
+ service_response.message.join(', ')
+ end
+
def quick_action_options
{
merge_request_diff_head_sha: params[:merge_request_diff_head_sha],
diff --git a/app/services/notes/quick_actions_service.rb b/app/services/notes/quick_actions_service.rb
index 38f7a23ce29..cba7398ebc0 100644
--- a/app/services/notes/quick_actions_service.rb
+++ b/app/services/notes/quick_actions_service.rb
@@ -50,7 +50,21 @@ module Notes
update_params[:spend_time][:note_id] = note.id
end
- noteable_update_service(note, update_params).execute(note.noteable)
+ execute_update_service(note, update_params)
+ end
+
+ private
+
+ def execute_update_service(note, params)
+ service_response = noteable_update_service(note, params).execute(note.noteable)
+
+ service_errors = if service_response.respond_to?(:errors)
+ service_response.errors.full_messages
+ elsif service_response.respond_to?(:[]) && service_response[:status] == :error
+ service_response[:message]
+ end
+
+ service_errors.blank? ? ServiceResponse.success : ServiceResponse.error(message: service_errors)
end
def noteable_update_service(note, update_params)