Commit 7ffb8fc6 authored by Ariejan de Vroom's avatar Ariejan de Vroom
Browse files

Added specs for special cases

We don't execute web hooks when:
 * You create a new branch. Make sure you first create the branch, and then push any commits. This is the way Github works, so its expected behavior.
 * When tags are pushed.
parent 87276ad3ea51
...@@ -92,6 +92,11 @@ def web_url ...@@ -92,6 +92,11 @@ def web_url
end end
def execute_web_hooks(oldrev, newrev, ref) 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) data = web_hook_data(oldrev, newrev, ref)
web_hooks.each { |web_hook| web_hook.execute(data) } web_hooks.each { |web_hook| web_hook.execute(data) }
end end
...@@ -91,10 +91,31 @@ ...@@ -91,10 +91,31 @@
@webhook.should_receive(:execute).once @webhook.should_receive(:execute).once
@webhook_2.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
end end
context "does not execute web hooks" do
before do
@webhook = Factory(:web_hook)
project.web_hooks << [@webhook]
it "when pushing a branch for the first time" do
project.execute_web_hooks('00000000000000000000000000000000', 'newrev', 'refs/heads/mster')
it "when pushing tags" do
project.execute_web_hooks('oldrev', 'newrev', 'refs/tags/v1.0.0')
context "when pushing new branches" do
context "when gathering commit data" do context "when gathering commit data" do
before do before do
@oldrev, @newrev, @ref = project.fresh_commits(2).last.sha, project.fresh_commits(2).first.sha, 'refs/heads/master' @oldrev, @newrev, @ref = project.fresh_commits(2).last.sha, project.fresh_commits(2).first.sha, 'refs/heads/master'
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment