Commit 84d28209 authored by Douwe Maan's avatar Douwe Maan

Use PushDataBuilder where applicable.

parent 4e49f21b
......@@ -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
......@@ -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)
......
......@@ -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
......@@ -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
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment