Skip to content

Commit

Permalink
Merge pull request #101 from CocoaPods/slack_disputes
Browse files Browse the repository at this point in the history
Notify Slack of new disputes
  • Loading branch information
floere committed Jul 24, 2014
2 parents 31c92be + 0a4518f commit 490fbe0
Showing 1 changed file with 26 additions and 1 deletion.
27 changes: 26 additions & 1 deletion app/controllers/claims_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
require 'active_support/core_ext/object/to_query'
require 'sinatra/twitter-bootstrap'
require 'slim'
require 'rest'

module Pod
module TrunkApp
Expand Down Expand Up @@ -61,7 +62,8 @@ class ClaimsController < HTMLController

post '/disputes' do
claimer = Owner.find_by_email(params[:dispute][:claimer_email])
Dispute.create(:claimer => claimer, :message => params[:dispute][:message])
dispute = Dispute.create(:claimer => claimer, :message => params[:dispute][:message])
notify_slack_of_dispute(dispute)
redirect to('/disputes/thanks')
end

Expand Down Expand Up @@ -131,6 +133,29 @@ def change_ownership
end
end
end

SLACK_DISPUTE_URL = 'https://cocoapods.slack.com/services/hooks/' \
"incoming-webhook?token=#{ENV['SLACK_DISPUTE_TOKEN']}"

def notify_slack_of_dispute(dispute)
link = "https://trunk.cocoapods.org/manage/disputes/#{dispute.id}"
REST.post(SLACK_DISPUTE_URL,
{
:attachments => [{
:fallback => "New dispute on trunk [Urgent]: <#{link}>",
:pretext => "There's a new dispute on trunk [Urgent]: <#{link}>",
:color => :warning,
:fields => [{
:title => 'Dispute by ' \
"#{dispute.claimer.name} (#{dispute.claimer.email})",
:value => dispute.message,
:short => false
}]
}]
}.to_json)
rescue REST::Error
"RuboCop: If REST has problems POSTing to Slack, we don't care."
end
end
end
end

0 comments on commit 490fbe0

Please sign in to comment.