Class: MergeRequests::AddContextService

Inherits:
BaseService show all
Defined in:
app/services/merge_requests/add_context_service.rb

Instance Attribute Summary

Attributes inherited from BaseContainerService

#container, #current_user, #group, #params, #project

Instance Method Summary collapse

Methods inherited from BaseService

#cancel_review_app_jobs!, #cleanup_environments, #create_note, #execute_external_hooks, #execute_group_mention_hooks, #execute_hooks, #handle_assignees_change, #handle_changes, #handle_reviewers_change, #hook_data, #initialize, #inspect, #merge_request_activity_counter, #source_project, #target_project

Methods included from Gitlab::Utils::Override

#extended, extensions, #included, #method_added, #override, #prepended, #queue_verification, verify!

Methods included from ErrorLogger

#log_error

Methods included from AssignsMergeParams

#assign_allowed_merge_params, included

Methods inherited from BaseContainerService

#group_container?, #initialize, #namespace_container?, #project_container?, #project_group

Methods included from BaseServiceUtility

#deny_visibility_level, #event_service, #log_error, #log_info, #notification_service, #system_hook_service, #todo_service, #visibility_level

Methods included from Gitlab::Allowable

#can?

Constructor Details

This class inherits a constructor from MergeRequests::BaseService

Instance Method Details

#executeObject



5
6
7
8
9
10
11
12
13
14
15
16
17
# File 'app/services/merge_requests/add_context_service.rb', line 5

def execute
  return error("You are not allowed to access the requested resource", 403) unless current_user&.can?(:update_merge_request, merge_request)
  return error("Context commits: #{duplicates} are already created", 400) unless duplicates.empty?
  return error("One or more context commits' sha is not valid.", 400) if commits.size != commit_ids.size

  context_commit_ids = []
  MergeRequestContextCommit.transaction do
    context_commit_ids = MergeRequestContextCommit.bulk_insert(context_commit_rows, return_ids: true)
    MergeRequestContextCommitDiffFile.bulk_insert(diff_rows(context_commit_ids))
  end

  commits
end