Commit 80ea525a authored by Nick Thomas's avatar Nick Thomas

Rename GitTagPushService -> Git::TagPushService

parent e27f4c9c
# frozen_string_literal: true
module Git
class TagPushService < BaseService
attr_accessor :push_data
def execute
project.repository.after_create if project.empty_repo?
project.repository.before_push_tag
@push_data = build_push_data
EventCreateService.new.push(project, current_user, push_data)
Ci::CreatePipelineService.new(project, current_user, push_data).execute(:push, pipeline_options)
SystemHooksService.new.execute_hooks(build_system_push_data, :tag_push_hooks)
project.execute_hooks(push_data.dup, :tag_push_hooks)
project.execute_services(push_data.dup, :tag_push_hooks)
ProjectCacheWorker.perform_async(project.id, [], [:commit_count, :repository_size])
true
end
private
def build_push_data
commits = []
message = nil
unless Gitlab::Git.blank_ref?(params[:newrev])
tag_name = Gitlab::Git.ref_name(params[:ref])
tag = project.repository.find_tag(tag_name)
if tag && tag.target == params[:newrev]
commit = project.commit(tag.dereferenced_target)
commits = [commit].compact
message = tag.message
end
end
Gitlab::DataBuilder::Push.build(
project,
current_user,
params[:oldrev],
params[:newrev],
params[:ref],
commits,
message,
push_options: params[:push_options] || [])
end
def build_system_push_data
Gitlab::DataBuilder::Push.build(
project,
current_user,
params[:oldrev],
params[:newrev],
params[:ref],
[],
'')
end
def pipeline_options
{} # to be overridden in EE
end
end
end
Git::TagPushService.prepend(EE::Git::TagPushService)
# frozen_string_literal: true
class GitTagPushService < BaseService
attr_accessor :push_data
def execute
project.repository.after_create if project.empty_repo?
project.repository.before_push_tag
@push_data = build_push_data
EventCreateService.new.push(project, current_user, push_data)
Ci::CreatePipelineService.new(project, current_user, push_data).execute(:push, pipeline_options)
SystemHooksService.new.execute_hooks(build_system_push_data, :tag_push_hooks)
project.execute_hooks(push_data.dup, :tag_push_hooks)
project.execute_services(push_data.dup, :tag_push_hooks)
ProjectCacheWorker.perform_async(project.id, [], [:commit_count, :repository_size])
true
end
private
def build_push_data
commits = []
message = nil
unless Gitlab::Git.blank_ref?(params[:newrev])
tag_name = Gitlab::Git.ref_name(params[:ref])
tag = project.repository.find_tag(tag_name)
if tag && tag.target == params[:newrev]
commit = project.commit(tag.dereferenced_target)
commits = [commit].compact
message = tag.message
end
end
Gitlab::DataBuilder::Push.build(
project,
current_user,
params[:oldrev],
params[:newrev],
params[:ref],
commits,
message,
push_options: params[:push_options] || [])
end
def build_system_push_data
Gitlab::DataBuilder::Push.build(
project,
current_user,
params[:oldrev],
params[:newrev],
params[:ref],
[],
'')
end
def pipeline_options
{} # to be overridden in EE
end
end
GitTagPushService.prepend(EE::GitTagPushService)
......@@ -38,7 +38,7 @@ class PostReceive
post_received.changes_refs do |oldrev, newrev, ref|
if Gitlab::Git.tag_ref?(ref)
GitTagPushService.new(
Git::TagPushService.new(
post_received.project,
@user,
oldrev: oldrev,
......
# frozen_string_literal: true
module EE
module Git
module TagPushService
extend ::Gitlab::Utils::Override
private
override :pipeline_options
def pipeline_options
{ mirror_update: params[:mirror_update] }
end
end
end
end
# frozen_string_literal: true
module EE
module GitTagPushService
extend ::Gitlab::Utils::Override
private
override :pipeline_options
def pipeline_options
{ mirror_update: params[:mirror_update] }
end
end
end
......@@ -79,7 +79,7 @@ module Projects
next if old_tag_target == tag_target
GitTagPushService.new(
Git::TagPushService.new(
project,
current_user,
{
......
......@@ -59,10 +59,10 @@ describe Projects::UpdateMirrorService do
expect(project.repository.tag_names).to include('new-tag')
end
it "only invokes GitTagPushService for tags pointing to commits" do
it "only invokes Git::TagPushService for tags pointing to commits" do
stub_fetch_mirror(project)
expect(GitTagPushService).to receive(:new)
expect(Git::TagPushService).to receive(:new)
.with(project, project.owner, hash_including(ref: 'refs/tags/new-tag'))
.and_return(double(execute: true))
......
......@@ -22,7 +22,7 @@ describe PostReceive do
allow_any_instance_of(Gitlab::DataBuilder::Repository).to receive(:update).and_return(fake_hook_data)
# silence hooks so we can isolate
allow_any_instance_of(Key).to receive(:post_create_hook).and_return(true)
allow_any_instance_of(GitTagPushService).to receive(:execute).and_return(true)
allow_any_instance_of(Git::TagPushService).to receive(:execute).and_return(true)
allow_any_instance_of(GitPushService).to receive(:execute).and_return(true)
end
......
require 'spec_helper'
describe GitTagPushService do
describe Git::TagPushService do
include RepoHelpers
include GitHelpers
......
......@@ -34,7 +34,7 @@ describe PostReceive do
context 'empty changes' do
it "does not call any PushService but runs after project hooks" do
expect(GitPushService).not_to receive(:new)
expect(GitTagPushService).not_to receive(:new)
expect(Git::TagPushService).not_to receive(:new)
expect_next_instance_of(SystemHooksService) { |service| expect(service).to receive(:execute_hooks) }
described_class.new.perform(gl_repository, key_id, "")
......@@ -46,7 +46,7 @@ describe PostReceive do
it 'returns false' do
expect(GitPushService).not_to receive(:new)
expect(GitTagPushService).not_to receive(:new)
expect(Git::TagPushService).not_to receive(:new)
expect(described_class.new.perform(gl_repository, key_id, base64_changes)).to be false
end
......@@ -62,7 +62,7 @@ describe PostReceive do
it "calls GitPushService" do
expect_any_instance_of(GitPushService).to receive(:execute).and_return(true)
expect_any_instance_of(GitTagPushService).not_to receive(:execute)
expect_any_instance_of(Git::TagPushService).not_to receive(:execute)
described_class.new.perform(gl_repository, key_id, base64_changes)
end
end
......@@ -70,9 +70,9 @@ describe PostReceive do
context "tags" do
let(:changes) { "123456 789012 refs/tags/tag" }
it "calls GitTagPushService" do
it "calls Git::TagPushService" do
expect_any_instance_of(GitPushService).not_to receive(:execute)
expect_any_instance_of(GitTagPushService).to receive(:execute).and_return(true)
expect_any_instance_of(Git::TagPushService).to receive(:execute).and_return(true)
described_class.new.perform(gl_repository, key_id, base64_changes)
end
end
......@@ -82,7 +82,7 @@ describe PostReceive do
it "does not call any of the services" do
expect_any_instance_of(GitPushService).not_to receive(:execute)
expect_any_instance_of(GitTagPushService).not_to receive(:execute)
expect_any_instance_of(Git::TagPushService).not_to receive(:execute)
described_class.new.perform(gl_repository, key_id, base64_changes)
end
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