summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>2014-04-01 10:33:23 +0300
committerDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>2014-04-01 10:33:23 +0300
commit95b84e2c5aa92a5a8effc108fdbdf596dff4818c (patch)
tree0ee296ccfd9ef9cc2157a4915ebee2ddfaa8bdb1
parent8f3701eff005aeedcebff8ce02074f5056a369b3 (diff)
downloadgitlab-ce-95b84e2c5aa92a5a8effc108fdbdf596dff4818c.tar.gz
Move branch creation logic in service
Signed-off-by: Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>
-rw-r--r--app/controllers/projects/branches_controller.rb6
-rw-r--r--app/services/create_branch_service.rb13
2 files changed, 14 insertions, 5 deletions
diff --git a/app/controllers/projects/branches_controller.rb b/app/controllers/projects/branches_controller.rb
index aa6914414ce..6a6cbe48184 100644
--- a/app/controllers/projects/branches_controller.rb
+++ b/app/controllers/projects/branches_controller.rb
@@ -16,11 +16,7 @@ class Projects::BranchesController < Projects::ApplicationController
end
def create
- @repository.add_branch(params[:branch_name], params[:ref])
-
- if new_branch = @repository.find_branch(params[:branch_name])
- Event.create_ref_event(@project, current_user, new_branch, 'add')
- end
+ CreateBranchService.new.execute(project, params[:branch_name], params[:ref], current_user)
redirect_to project_branches_path(@project)
end
diff --git a/app/services/create_branch_service.rb b/app/services/create_branch_service.rb
new file mode 100644
index 00000000000..98beeee8354
--- /dev/null
+++ b/app/services/create_branch_service.rb
@@ -0,0 +1,13 @@
+class CreateBranchService
+ def execute(project, branch_name, ref, current_user)
+ repository = project.repository
+ repository.add_branch(branch_name, ref)
+ new_branch = repository.find_branch(branch_name)
+
+ if new_branch
+ Event.create_ref_event(project, current_user, new_branch, 'add')
+ end
+
+ new_branch
+ end
+end