Class: MergeRequests::PushOptionsHandlerService

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

Constant Summary collapse

LIMIT =
10

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(project, current_user, changes, push_options) ⇒ PushOptionsHandlerService

Returns a new instance of PushOptionsHandlerService.


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

def initialize(project, current_user, changes, push_options)
  @project = project
  @target_project = @project.default_merge_request_target
  @current_user = current_user
  @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

#current_userObject (readonly)

Returns the value of attribute current_user


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

def current_user
  @current_user
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

#projectObject (readonly)

Returns the value of attribute project


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

def project
  @project
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


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

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