diff options
Diffstat (limited to 'app/services')
-rw-r--r-- | app/services/create_branch_service.rb | 14 | ||||
-rw-r--r-- | app/services/create_tag_service.rb | 4 | ||||
-rw-r--r-- | app/services/delete_branch_service.rb | 11 | ||||
-rw-r--r-- | app/services/event_create_service.rb | 20 |
4 files changed, 22 insertions, 27 deletions
diff --git a/app/services/create_branch_service.rb b/app/services/create_branch_service.rb index 5e971c7891c..f835f06e72b 100644 --- a/app/services/create_branch_service.rb +++ b/app/services/create_branch_service.rb @@ -17,10 +17,13 @@ class CreateBranchService < BaseService new_branch = repository.find_branch(branch_name) if new_branch - EventCreateService.new.push_ref(project, current_user, new_branch, 'add') - return success(new_branch) + push_data = build_push_data(project, current_user, new_branch) + + EventCreateService.new.push(project, current_user, push_data) + + success(new_branch) else - return error('Invalid reference name') + error('Invalid reference name') end end @@ -29,4 +32,9 @@ class CreateBranchService < BaseService out[:branch] = branch out end + + def build_push_data(project, user, branch) + Gitlab::PushDataBuilder. + build(project, user, Gitlab::Git::BLANK_SHA, branch.target, "#{Gitlab::Git::BRANCH_REF_PREFIX}#{branch.name}", []) + end end diff --git a/app/services/create_tag_service.rb b/app/services/create_tag_service.rb index 755202310ab..af4b537cb93 100644 --- a/app/services/create_tag_service.rb +++ b/app/services/create_tag_service.rb @@ -21,9 +21,9 @@ class CreateTagService < BaseService new_tag = repository.find_tag(tag_name) if new_tag - EventCreateService.new.push_ref(project, current_user, new_tag, 'add', Gitlab::Git::TAG_REF_PREFIX) - push_data = create_push_data(project, current_user, new_tag) + + EventCreateService.new.push(project, current_user, push_data) project.execute_hooks(push_data.dup, :tag_push_hooks) project.execute_services(push_data.dup, :tag_push_hooks) diff --git a/app/services/delete_branch_service.rb b/app/services/delete_branch_service.rb index c26aee2b0aa..f2d5ed818c1 100644 --- a/app/services/delete_branch_service.rb +++ b/app/services/delete_branch_service.rb @@ -25,10 +25,12 @@ class DeleteBranchService < BaseService end if repository.rm_branch(branch_name) - EventCreateService.new.push_ref(project, current_user, branch, 'rm') + push_data = build_push_data(branch) + + EventCreateService.new.push(project, current_user, push_data) success('Branch was removed') else - return error('Failed to remove branch') + error('Failed to remove branch') end end @@ -43,4 +45,9 @@ class DeleteBranchService < BaseService out[:message] = message out end + + def build_push_data(branch) + Gitlab::PushDataBuilder + .build(project, current_user, branch.target, Gitlab::Git::BLANK_SHA, "#{Gitlab::Git::BRANCH_REF_PREFIX}#{branch.name}", []) + end end diff --git a/app/services/event_create_service.rb b/app/services/event_create_service.rb index dc52d6d89df..103d6b0a08b 100644 --- a/app/services/event_create_service.rb +++ b/app/services/event_create_service.rb @@ -62,26 +62,6 @@ class EventCreateService create_event(project, current_user, Event::CREATED) end - def push_ref(project, current_user, ref, action = 'add', prefix = Gitlab::Git::BRANCH_REF_PREFIX) - commit = project.repository.commit(ref.target) - - if action.to_s == 'add' - before = Gitlab::Git::BLANK_SHA - after = commit.id - else - before = commit.id - after = Gitlab::Git::BLANK_SHA - end - - data = { - ref: "#{prefix}#{ref.name}", - before: before, - after: after - } - - push(project, current_user, data) - end - def push(project, current_user, push_data) create_event(project, current_user, Event::PUSHED, data: push_data) end |