Class: Branches::ValidateNewService

Inherits:
BaseService show all
Defined in:
app/services/branches/validate_new_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) ⇒ ValidateNewService

Returns a new instance of ValidateNewService.


5
6
7
# File 'app/services/branches/validate_new_service.rb', line 5

def initialize(project)
  @project = project
end

Instance Method Details

#execute(branch_name, force: false) ⇒ Object


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

def execute(branch_name, force: false)
  return error('Branch name is invalid') unless valid_name?(branch_name)

  if branch_exist?(branch_name) && !force
    return error('Branch already exists')
  end

  success
rescue Gitlab::Git::PreReceiveError => ex
  error(ex.message)
end