Commit 13d2bcc3b4d6141643fe31dc4d7212ebca0612a5
1 parent
9a676ccc
Exists in
spb-stable
and in
3 other branches
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.
Showing
2 changed files
with
68 additions
and
0 deletions
Show diff stats
@@ -0,0 +1,25 @@ | @@ -0,0 +1,25 @@ | ||
1 | +class GitTagPushService | ||
2 | + attr_accessor :project, :user, :push_data | ||
3 | + def execute(project, user, ref) | ||
4 | + @project, @user = project, user | ||
5 | + @push_data = create_push_data(ref) | ||
6 | + project.execute_hooks(@push_data.dup, :tag_push_hooks) | ||
7 | + end | ||
8 | + | ||
9 | + private | ||
10 | + | ||
11 | + def create_push_data(ref) | ||
12 | + data = { | ||
13 | + ref: ref, | ||
14 | + user_id: user.id, | ||
15 | + user_name: user.name, | ||
16 | + project_id: project.id, | ||
17 | + repository: { | ||
18 | + name: project.name, | ||
19 | + url: project.url_to_repo, | ||
20 | + description: project.description, | ||
21 | + homepage: project.web_url | ||
22 | + } | ||
23 | + } | ||
24 | + end | ||
25 | +end |
@@ -0,0 +1,43 @@ | @@ -0,0 +1,43 @@ | ||
1 | +require 'spec_helper' | ||
2 | + | ||
3 | +describe GitTagPushService do | ||
4 | + let (:user) { create :user } | ||
5 | + let (:project) { create :project } | ||
6 | + let (:service) { GitTagPushService.new } | ||
7 | + | ||
8 | + before do | ||
9 | + @ref = 'refs/tags/super-tag' | ||
10 | + end | ||
11 | + | ||
12 | + describe 'Git Tag Push Data' do | ||
13 | + before do | ||
14 | + service.execute(project, user, @ref) | ||
15 | + @push_data = service.push_data | ||
16 | + end | ||
17 | + | ||
18 | + subject { @push_data } | ||
19 | + | ||
20 | + it { should include(ref: @ref) } | ||
21 | + it { should include(user_id: user.id) } | ||
22 | + it { should include(user_name: user.name) } | ||
23 | + it { should include(project_id: project.id) } | ||
24 | + | ||
25 | + context 'With repository data' do | ||
26 | + subject { @push_data[:repository] } | ||
27 | + | ||
28 | + it { should include(name: project.name) } | ||
29 | + it { should include(url: project.url_to_repo) } | ||
30 | + it { should include(description: project.description) } | ||
31 | + it { should include(homepage: project.web_url) } | ||
32 | + end | ||
33 | + end | ||
34 | + | ||
35 | + describe "Web Hooks" do | ||
36 | + context "execute web hooks" do | ||
37 | + it "when pushing tags" do | ||
38 | + project.should_receive(:execute_hooks) | ||
39 | + service.execute(project, user, 'refs/tags/v1.0.0') | ||
40 | + end | ||
41 | + end | ||
42 | + end | ||
43 | +end |