Commit 4a251849cf0408780f6ee536699c212f8fe7a7be

Authored by Jeroen van Baarsen
1 parent f096bd61

Added newrev and oldrev to the hook data

app/services/git_tag_push_service.rb
1 1 class GitTagPushService
2 2 attr_accessor :project, :user, :push_data
3   - def execute(project, user, ref)
  3 + def execute(project, user, oldrev, newrev, ref)
4 4 @project, @user = project, user
5   - @push_data = create_push_data(ref)
  5 + @push_data = create_push_data(oldrev, newrev, ref)
6 6 project.execute_hooks(@push_data.dup, :tag_push_hooks)
7 7 end
8 8  
9 9 private
10 10  
11   - def create_push_data(ref)
  11 + def create_push_data(oldrev, newrev, ref)
12 12 data = {
13 13 ref: ref,
  14 + oldrev: oldrev,
  15 + newrev: newrev,
14 16 user_id: user.id,
15 17 user_name: user.name,
16 18 project_id: project.id,
... ...
app/workers/post_receive.rb
... ... @@ -30,7 +30,7 @@ class PostReceive
30 30 end
31 31  
32 32 if tag?(ref)
33   - GitTagPushService.new.execute(project, user, ref)
  33 + GitTagPushService.new.execute(project, user, oldrev, newrev, ref)
34 34 else
35 35 GitPushService.new.execute(project, user, oldrev, newrev, ref)
36 36 end
... ...
spec/services/git_tag_push_service_spec.rb
... ... @@ -7,17 +7,21 @@ describe GitTagPushService do
7 7  
8 8 before do
9 9 @ref = 'refs/tags/super-tag'
  10 + @oldrev = 'b98a310def241a6fd9c9a9a3e7934c48e498fe81'
  11 + @newrev = 'b19a04f53caeebf4fe5ec2327cb83e9253dc91bb'
10 12 end
11 13  
12 14 describe 'Git Tag Push Data' do
13 15 before do
14   - service.execute(project, user, @ref)
  16 + service.execute(project, user, @oldrev, @newrev, @ref)
15 17 @push_data = service.push_data
16 18 end
17 19  
18 20 subject { @push_data }
19 21  
20 22 it { should include(ref: @ref) }
  23 + it { should include(oldrev: @oldrev) }
  24 + it { should include(newrev: @newrev) }
21 25 it { should include(user_id: user.id) }
22 26 it { should include(user_name: user.name) }
23 27 it { should include(project_id: project.id) }
... ... @@ -36,7 +40,7 @@ describe GitTagPushService do
36 40 context "execute web hooks" do
37 41 it "when pushing tags" do
38 42 project.should_receive(:execute_hooks)
39   - service.execute(project, user, 'refs/tags/v1.0.0')
  43 + service.execute(project, user, 'oldrev', 'newrev', 'refs/tags/v1.0.0')
40 44 end
41 45 end
42 46 end
... ...