Skip to content
Snippets Groups Projects
Commit 84d28209 authored by Douwe Maan's avatar Douwe Maan
Browse files

Use PushDataBuilder where applicable.

parent 4e49f21b
No related branches found
No related tags found
No related merge requests found
Loading
Loading
@@ -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
 
Loading
Loading
@@ -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
Loading
Loading
@@ -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)
 
Loading
Loading
Loading
Loading
@@ -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
 
Loading
Loading
@@ -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
Loading
Loading
@@ -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
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment