Created a basic Git Tag Push service
This is the first version, and only has the most basic information about the tag that is created.
This commit is contained in:
parent
9a676ccc0a
commit
13d2bcc3b4
2 changed files with 68 additions and 0 deletions
25
app/services/git_tag_push_service.rb
Normal file
25
app/services/git_tag_push_service.rb
Normal file
|
@ -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
|
43
spec/services/git_tag_push_service_spec.rb
Normal file
43
spec/services/git_tag_push_service_spec.rb
Normal file
|
@ -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
|
Loading…
Reference in a new issue