Class: Branches::CreateService

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

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(project, user = nil, params = {}) ⇒ CreateService

Returns a new instance of CreateService.



5
6
7
8
9
# File 'app/services/branches/create_service.rb', line 5

def initialize(project, user = nil, params = {})
  super(project, user, params)

  @errors = []
end

Instance Method Details

#bulk_create(branches) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'app/services/branches/create_service.rb', line 21

def bulk_create(branches)
  reset_errors

  created_branches =
    branches
      .then { |branches| only_valid_branches(branches) }
      .then { |branches| create_branches(branches) }
      .then { |branches| expire_branches_cache(branches) }

  return error(errors) if errors.present?

  success(branches: created_branches)
end

#execute(branch_name, ref, create_default_branch_if_empty: true) ⇒ Object



11
12
13
14
15
16
17
18
19
# File 'app/services/branches/create_service.rb', line 11

def execute(branch_name, ref, create_default_branch_if_empty: true)
  create_default_branch if create_default_branch_if_empty && project.empty_repo?

  result = branch_validation_service.execute(branch_name)

  return result if result[:status] == :error

  create_branch(branch_name, ref)
end