Permalink
Browse files

Add support for inline bundler API trigger

  • Loading branch information...
1 parent 4362cdd commit f8b9732f45960fafe33e1fd12d354fc734957aaf @evanphx evanphx committed Jan 2, 2013
Showing with 43 additions and 0 deletions.
  1. +21 −0 app/models/pusher.rb
  2. +22 −0 test/unit/pusher_test.rb
View
@@ -1,11 +1,14 @@
class Pusher
attr_reader :user, :spec, :message, :code, :rubygem, :body, :version, :version_id
+ attr_accessor :bundler_api_url
def initialize(user, body, host_with_port=nil)
@user = user
@body = StringIO.new(body.read)
@indexer = Indexer.new
@host_with_port = host_with_port
+ @bundler_token = ENV['BUNDLER_TOKEN'] || "tokenmeaway"
+ @bundler_api_url = ENV['BUNDLER_API_URL']
end
def process
@@ -62,12 +65,30 @@ def inspect
"<Pusher #{attrs.join(' ')}>"
end
+ def update_remote_bundler_api(to=RestClient)
+ return unless @bundler_api_url
+
+ json = %Q!{ "name": "#{spec.name}", "version": "#{spec.version}", "platform": "#{spec.platform}", "prerelease": #{spec.version.prerelease? ? 'true' : 'false'}, "rubygems_token": "#{@bundler_token}"}!
+
+ begin
+ timeout(5) do
+ to.post @bundler_api_url,
+ json,
+ :timeout => 5,
+ :open_timeout => 5,
+ 'Content-Type' => 'application/json'
+ end
+ rescue StandardError, Interrupt
+ false
+ end
+ end
private
def after_write
@version_id = version.id
Delayed::Job.enqueue Indexer.new, :priority => PRIORITIES[:push]
enqueue_web_hook_jobs
+ update_remote_bundler_api
end
def notify(message, code)
View
@@ -80,6 +80,28 @@ class PusherTest < ActiveSupport::TestCase
assert_equal @cutter.code, 422
end
+ should "post info to the remote bundler API" do
+ @cutter.pull_spec
+
+ @cutter.bundler_api_url = "http://test.com"
+
+ obj = Object.new
+ post_data = nil
+
+ stub(obj).post { |*x| post_data = x }
+
+ @cutter.update_remote_bundler_api obj
+
+ url, payload, options = post_data
+
+ params = MultiJson.load payload
+
+ assert_equal "test", params["name"]
+ assert_equal "0.0.0", params["version"]
+ assert_equal "ruby", params["platform"]
+ assert_equal false, params["prerelease"]
+ end
+
context "finding rubygem" do
should "initialize new gem if one does not exist" do
spec = "spec"

0 comments on commit f8b9732

Please sign in to comment.