Permalink
Browse files

Pass failing yank/unyank webhook scenarios

  • Loading branch information...
1 parent daec78c commit c3aa7ec5c62abba23b72c435af484faa1e50a15b @laserlemon laserlemon committed Nov 21, 2011
@@ -31,6 +31,9 @@ def create
def yank
if @version.indexed?
@rubygem.yank!(@version)
+ (@rubygem.web_hooks + WebHook.global).each do |web_hook|
+ web_hook.fire("yank", request.host_with_port, @rubygem, @version, true)
+ end
render :text => "Successfully yanked gem: #{@version.to_title}"
else
render :text => "The version #{params[:version]} has already been yanked.", :status => :unprocessable_entity
@@ -40,6 +43,9 @@ def yank
def unyank
if !@version.indexed?
@version.unyank!
+ (@rubygem.web_hooks + WebHook.global).each do |web_hook|
+ web_hook.fire("unyank", request.host_with_port, @rubygem, @version, true)
+ end
render :text => "Successfully unyanked gem: #{@version.to_title}"
else
render :text => "The version #{params[:version]} is already indexed.", :status => :unprocessable_entity
@@ -31,7 +31,7 @@ def fire
webhook = current_user.web_hooks.new(:url => @url)
@rubygem = Rubygem.find_by_name("gemcutter") unless @rubygem
- if webhook.fire(request.host_with_port, @rubygem, @rubygem.versions.most_recent, false)
+ if webhook.fire("push", request.host_with_port, @rubygem, @rubygem.versions.most_recent, false)
render :text => webhook.deployed_message(@rubygem)
else
render :text => webhook.failed_message(@rubygem), :status => :bad_request
View
@@ -1,8 +1,8 @@
-class Notifier < Struct.new(:url, :host_with_port, :rubygem, :version, :api_key)
+class Notifier < Struct.new(:event, :url, :host_with_port, :rubygem, :version, :api_key)
def payload
payload = rubygem.payload(version, host_with_port)
- payload.merge("event" => "push", "payload" => payload).to_json
+ payload.merge("event" => event, "payload" => payload).to_json
end
def authorization
View
@@ -91,7 +91,7 @@ def inspect
def enqueue_web_hook_jobs
jobs = rubygem.web_hooks + WebHook.global
jobs.each do |job|
- job.fire(@host_with_port, rubygem, version)
+ job.fire("push", @host_with_port, rubygem, version)
end
end
end
View
@@ -15,8 +15,8 @@ def self.specific
where("rubygem_id is not null")
end
- def fire(host_with_port, deploy_gem, version, delayed=true)
- job = Notifier.new(self.url, host_with_port, deploy_gem, version, self.user.api_key)
+ def fire(event, host_with_port, deploy_gem, version, delayed=true)
+ job = Notifier.new(event, url, host_with_port, deploy_gem, version, user.api_key)
if delayed
Delayed::Job.enqueue job, :priority => PRIORITIES[:web_hook]
else

0 comments on commit c3aa7ec

Please sign in to comment.