diff --git a/app/services/git_tag_push_service.rb b/app/services/git_tag_push_service.rb new file mode 100644 index 00000000000..21db5fcfa58 --- /dev/null +++ b/app/services/git_tag_push_service.rb @@ -0,0 +1,25 @@ +class GitTagPushService + attr_accessor :project, :user, :push_data + def execute(project, user, ref) + @project, @user = project, user + @push_data = create_push_data(ref) + project.execute_hooks(@push_data.dup, :tag_push_hooks) + end + + private + + def create_push_data(ref) + data = { + ref: ref, + user_id: user.id, + user_name: user.name, + project_id: project.id, + repository: { + name: project.name, + url: project.url_to_repo, + description: project.description, + homepage: project.web_url + } + } + end +end diff --git a/spec/services/git_tag_push_service_spec.rb b/spec/services/git_tag_push_service_spec.rb new file mode 100644 index 00000000000..aabb9f8f38d --- /dev/null +++ b/spec/services/git_tag_push_service_spec.rb @@ -0,0 +1,43 @@ +require 'spec_helper' + +describe GitTagPushService do + let (:user) { create :user } + let (:project) { create :project } + let (:service) { GitTagPushService.new } + + before do + @ref = 'refs/tags/super-tag' + end + + describe 'Git Tag Push Data' do + before do + service.execute(project, user, @ref) + @push_data = service.push_data + end + + subject { @push_data } + + it { should include(ref: @ref) } + it { should include(user_id: user.id) } + it { should include(user_name: user.name) } + it { should include(project_id: project.id) } + + context 'With repository data' do + subject { @push_data[:repository] } + + it { should include(name: project.name) } + it { should include(url: project.url_to_repo) } + it { should include(description: project.description) } + it { should include(homepage: project.web_url) } + end + end + + describe "Web Hooks" do + context "execute web hooks" do + it "when pushing tags" do + project.should_receive(:execute_hooks) + service.execute(project, user, 'refs/tags/v1.0.0') + end + end + end +end