Class: Submodules::UpdateService

Inherits:
Commits::CreateService show all
Includes:
Gitlab::Utils::StrongMemoize
Defined in:
app/services/submodules/update_service.rb

Constant Summary

Constants inherited from Commits::CreateService

Commits::CreateService::ValidationError

Instance Attribute Summary

Attributes inherited from BaseService

#current_user, #params, #project

Instance Method Summary collapse

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(*args) ⇒ UpdateService

Returns a new instance of UpdateService.



7
8
9
10
11
12
13
14
# File 'app/services/submodules/update_service.rb', line 7

def initialize(*args)
  super

  @start_branch = @branch_name
  @commit_sha = params[:commit_sha].presence
  @submodule = params[:submodule].presence
  @commit_message = params[:commit_message].presence || "Update submodule #{@submodule} with oid #{@commit_sha}"
end

Instance Method Details

#create_commit!Object



28
29
30
31
32
33
34
35
36
37
38
# File 'app/services/submodules/update_service.rb', line 28

def create_commit!
  repository.update_submodule(
    current_user,
    @submodule,
    @commit_sha,
    message: @commit_message,
    branch: @branch_name
  )
rescue ArgumentError, TypeError
  raise ValidationError, 'Invalid parameters'
end

#executeObject



22
23
24
25
26
# File 'app/services/submodules/update_service.rb', line 22

def execute
  super
rescue StandardError => e
  error(e.message)
end

#validate!Object

Raises:



16
17
18
19
20
# File 'app/services/submodules/update_service.rb', line 16

def validate!
  super

  raise ValidationError, 'The repository is empty' if repository.empty?
end