diff --git a/app/models/project.rb b/app/models/project.rb index e14c1ebf..ab21f4da 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -92,6 +92,11 @@ class Project < ActiveRecord::Base end def execute_web_hooks(oldrev, newrev, ref) + ref_parts = ref.split('/') + + # Return if this is not a push to a branch (e.g. new commits) + return if ref_parts[1] !~ /heads/ || oldrev == "00000000000000000000000000000000" + data = web_hook_data(oldrev, newrev, ref) web_hooks.each { |web_hook| web_hook.execute(data) } end diff --git a/spec/models/project_spec.rb b/spec/models/project_spec.rb index 0afb73f8..242461d0 100644 --- a/spec/models/project_spec.rb +++ b/spec/models/project_spec.rb @@ -91,10 +91,31 @@ describe Project do @webhook.should_receive(:execute).once @webhook_2.should_receive(:execute).once - project.execute_web_hooks('oldrev', 'newrev', 'ref') + project.execute_web_hooks('oldrev', 'newrev', 'refs/heads/master') end end + context "does not execute web hooks" do + before do + @webhook = Factory(:web_hook) + project.web_hooks << [@webhook] + end + + it "when pushing a branch for the first time" do + @webhook.should_not_receive(:execute) + project.execute_web_hooks('00000000000000000000000000000000', 'newrev', 'refs/heads/mster') + end + + it "when pushing tags" do + @webhook.should_not_receive(:execute) + project.execute_web_hooks('oldrev', 'newrev', 'refs/tags/v1.0.0') + end + end + + context "when pushing new branches" do + + end + context "when gathering commit data" do before do @oldrev, @newrev, @ref = project.fresh_commits(2).last.sha, project.fresh_commits(2).first.sha, 'refs/heads/master'