Class: Commits::CreateService

Inherits:
BaseService show all
Defined in:
app/services/commits/create_service.rb

Defined Under Namespace

Classes: ChangeError

Constant Summary collapse

ValidationError =
Class.new(StandardError)

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) ⇒ CreateService

Returns a new instance of CreateService.


16
17
18
19
20
21
22
23
24
25
# File 'app/services/commits/create_service.rb', line 16

def initialize(*args)
  super

  @start_project = params[:start_project] || @project
  @start_branch = params[:start_branch]
  @start_sha = params[:start_sha]
  @branch_name = params[:branch_name]
  @force = params[:force] || false
  @dry_run = params[:dry_run] || false
end

Instance Method Details

#executeObject


27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'app/services/commits/create_service.rb', line 27

def execute
  validate!

  new_commit = create_commit!

  success(result: new_commit)
rescue ChangeError => ex
  Gitlab::ErrorTracking.log_exception(ex)
  error(ex.message, pass_back: { error_code: ex.error_code })
rescue ValidationError,
       Gitlab::Git::Index::IndexError,
       Gitlab::Git::CommitError,
       Gitlab::Git::PreReceiveError,
       Gitlab::Git::CommandError => ex
  Gitlab::ErrorTracking.log_exception(ex)
  error(ex.message)
end