Permalink
Browse files

Setting multiple hook urls

  • Loading branch information...
1 parent 18d8237 commit 498f783b89a8c2523e2d632ddab7a12d74d56c4c @qrush qrush committed Jan 8, 2010
View
@@ -1,10 +1,20 @@
Feature: Set hooks
- Scenario: Adding a single collaborator for a specific project
+ Scenario: Adding a hook to a project
When I execute the following code
"""
Enforcer "thoughtbot", "deadbeef" do
postreceive "shoulda", "http://ci.thoughtbot.com"
end
"""
Then the GitHub API should have received a request to add "http://ci.thoughtbot.com" as a post-receive url for "shoulda"
+
+ Scenario: Adding hooks to a project
+ When I execute the following code
+ """
+ Enforcer "thoughtbot", "deadbeef" do
+ postreceive "shoulda", "http://ci.thoughtbot.com", "http://rdoc.info/projects/update"
+ end
+ """
+ Then the GitHub API should have received a request to add "http://ci.thoughtbot.com" as a post-receive url for "shoulda"
+ Then the GitHub API should have received a request to add "http://rdoc.info/projects/update" as a post-receive url for "shoulda"
@@ -31,5 +31,5 @@
end
Then /^the GitHub API should have received a request to add "([^\"]*)" as a post\-receive url for "([^\"]*)"$/ do |url, repo|
- assert_received(@repo) { |subject| subject.postreceive(url) }
+ assert_received(@repo) { |subject| subject.postreceive(satisfy { |urls| urls.include?(url) }) }
end
View
@@ -35,10 +35,12 @@ def project(project_name, *collaborators)
end
end
- def postreceive(project_name, url)
- STDOUT.puts "Enforcing post-receive url for #{project_name}"
+ def postreceive(project_name, *urls)
+ STDOUT.puts "Enforcing post-receive urls for #{project_name}"
+
repo = Repository.new(@account_name, @api_key, project_name)
- repo.postreceive(url)
+
+ repo.postreceive(urls)
end
end
@@ -39,16 +39,17 @@ def remove(collaborator)
request(:post, "/collaborators/#{@project}/remove/#{collaborator}")
end
- def postreceive(hook)
- auth = {:login => @account, :token => @api_key}
-
+ def postreceive(hooks)
url = URI.parse "https://github.com/#{@account}/#{@project}/edit/postreceive_urls"
+
req = Net::HTTP::Post.new(url.path)
- req.set_form_data({"urls[]" => hook}.merge(auth), '&')
+ req.body = "login=#{@account}&token=#{@api_key}&#{hooks.map { |hook| "urls[]=#{hook}" }.join('&')}"
+ req.content_type = 'application/x-www-form-urlencoded'
server = Net::HTTP.new url.host, url.port
server.use_ssl = url.scheme == 'https'
server.verify_mode = OpenSSL::SSL::VERIFY_NONE
+
res = server.start {|http| http.request(req) }
res.body
end
View
@@ -74,7 +74,15 @@ class EnforcerTest < Test::Unit::TestCase
@enforcer.postreceive @project, 'http://example.com'
assert_received(@repo) do |subject|
- subject.postreceive('http://example.com')
+ subject.postreceive(['http://example.com'])
+ end
+ end
+
+ should "add postreceive urls to the project" do
+ @enforcer.postreceive @project, 'http://example.com', 'http://ci.example.com'
+
+ assert_received(@repo) do |subject|
+ subject.postreceive(['http://example.com', 'http://ci.example.com'])
end
end
end

0 comments on commit 498f783

Please sign in to comment.