Commit 558e9462 authored by Nick Thomas's avatar Nick Thomas

Rename GitTagPushService -> Git::TagPushService

parent ed99296e
# 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
# 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
...@@ -38,7 +38,7 @@ class PostReceive ...@@ -38,7 +38,7 @@ class PostReceive
post_received.changes_refs do |oldrev, newrev, ref| post_received.changes_refs do |oldrev, newrev, ref|
if Gitlab::Git.tag_ref?(ref) if Gitlab::Git.tag_ref?(ref)
GitTagPushService.new( Git::TagPushService.new(
post_received.project, post_received.project,
@user, @user,
oldrev: oldrev, oldrev: oldrev,
......
require 'spec_helper' require 'spec_helper'
describe GitTagPushService do describe Git::TagPushService do
include RepoHelpers include RepoHelpers
include GitHelpers include GitHelpers
......
...@@ -34,7 +34,7 @@ describe PostReceive do ...@@ -34,7 +34,7 @@ describe PostReceive do
context 'empty changes' do context 'empty changes' do
it "does not call any PushService but runs after project hooks" do it "does not call any PushService but runs after project hooks" do
expect(GitPushService).not_to receive(:new) 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) } expect_next_instance_of(SystemHooksService) { |service| expect(service).to receive(:execute_hooks) }
described_class.new.perform(gl_repository, key_id, "") described_class.new.perform(gl_repository, key_id, "")
...@@ -46,7 +46,7 @@ describe PostReceive do ...@@ -46,7 +46,7 @@ describe PostReceive do
it 'returns false' do it 'returns false' do
expect(GitPushService).not_to receive(:new) 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 expect(described_class.new.perform(gl_repository, key_id, base64_changes)).to be false
end end
...@@ -62,7 +62,7 @@ describe PostReceive do ...@@ -62,7 +62,7 @@ describe PostReceive do
it "calls GitPushService" do it "calls GitPushService" do
expect_any_instance_of(GitPushService).to receive(:execute).and_return(true) 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) described_class.new.perform(gl_repository, key_id, base64_changes)
end end
end end
...@@ -70,9 +70,9 @@ describe PostReceive do ...@@ -70,9 +70,9 @@ describe PostReceive do
context "tags" do context "tags" do
let(:changes) { "123456 789012 refs/tags/tag" } 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(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) described_class.new.perform(gl_repository, key_id, base64_changes)
end end
end end
...@@ -82,7 +82,7 @@ describe PostReceive do ...@@ -82,7 +82,7 @@ describe PostReceive do
it "does not call any of the services" do it "does not call any of the services" do
expect_any_instance_of(GitPushService).not_to receive(:execute) 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) described_class.new.perform(gl_repository, key_id, base64_changes)
end end
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