Commit 95b84e2c5aa92a5a8effc108fdbdf596dff4818c

Authored by Dmitriy Zaporozhets
1 parent 8f3701ef

Move branch creation logic in service

Signed-off-by: Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>
app/controllers/projects/branches_controller.rb
... ... @@ -16,11 +16,7 @@ class Projects::BranchesController &lt; Projects::ApplicationController
16 16 end
17 17  
18 18 def create
19   - @repository.add_branch(params[:branch_name], params[:ref])
20   -
21   - if new_branch = @repository.find_branch(params[:branch_name])
22   - Event.create_ref_event(@project, current_user, new_branch, 'add')
23   - end
  19 + CreateBranchService.new.execute(project, params[:branch_name], params[:ref], current_user)
24 20  
25 21 redirect_to project_branches_path(@project)
26 22 end
... ...
app/services/create_branch_service.rb 0 → 100644
... ... @@ -0,0 +1,13 @@
  1 +class CreateBranchService
  2 + def execute(project, branch_name, ref, current_user)
  3 + repository = project.repository
  4 + repository.add_branch(branch_name, ref)
  5 + new_branch = repository.find_branch(branch_name)
  6 +
  7 + if new_branch
  8 + Event.create_ref_event(project, current_user, new_branch, 'add')
  9 + end
  10 +
  11 + new_branch
  12 + end
  13 +end
... ...