Class: MergeRequests::PushOptionsHandlerService

Inherits:
BaseProjectService show all
Defined in:
app/services/merge_requests/push_options_handler_service.rb

Constant Summary collapse

LIMIT =
10

Instance Attribute Summary collapse

Attributes inherited from BaseProjectService

#project

Attributes inherited from BaseContainerService

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

Instance Method Summary collapse

Methods inherited from BaseContainerService

#group_container?, #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

#initialize(project:, current_user:, changes:, push_options:, params: {}) ⇒ PushOptionsHandlerService

Returns a new instance of PushOptionsHandlerService.



9
10
11
12
13
14
15
16
# File 'app/services/merge_requests/push_options_handler_service.rb', line 9

def initialize(project:, current_user:, changes:, push_options:, params: {})
  super(project: project, current_user: current_user, params: params)

  @target_project = @project.default_merge_request_target
  @changes = Gitlab::ChangesList.new(changes)
  @push_options = push_options
  @errors = []
end

Instance Attribute Details

#changesObject (readonly)

Returns the value of attribute changes.



7
8
9
# File 'app/services/merge_requests/push_options_handler_service.rb', line 7

def changes
  @changes
end

#errorsObject (readonly)

Returns the value of attribute errors.



7
8
9
# File 'app/services/merge_requests/push_options_handler_service.rb', line 7

def errors
  @errors
end

#push_optionsObject (readonly)

Returns the value of attribute push_options.



7
8
9
# File 'app/services/merge_requests/push_options_handler_service.rb', line 7

def push_options
  @push_options
end

#target_projectObject (readonly)

Returns the value of attribute target_project.



7
8
9
# File 'app/services/merge_requests/push_options_handler_service.rb', line 7

def target_project
  @target_project
end

Instance Method Details

#executeObject



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'app/services/merge_requests/push_options_handler_service.rb', line 18

def execute
  validate_service
  return self if errors.present?

  branches.each do |branch|
    execute_for_branch(branch)
  rescue Gitlab::Access::AccessDeniedError
    errors << 'User access was denied'
  rescue StandardError => e
    Gitlab::AppLogger.error(e)
    errors << 'An unknown error occurred'
  end

  self
end