Commit e0fe8d1cd8bc26f33fd20a51cb70d8ce106fc491
Exists in
master
and in
1 other branch
Merge pull request #373 from luxflux/hubot-notification
Hubot notification service
Showing
8 changed files
with
51 additions
and
1 deletions
Show diff stats
Gemfile
Gemfile.lock
4.96 KB
4.96 KB
4.78 KB
| ... | ... | @@ -0,0 +1,32 @@ |
| 1 | +class NotificationServices::HubotService < NotificationService | |
| 2 | + Label = "hubot" | |
| 3 | + Fields = [ | |
| 4 | + [:api_token, { | |
| 5 | + :placeholder => 'http://hubot.example.org:8080/hubot/say', | |
| 6 | + :label => 'Hubot URL' | |
| 7 | + }], | |
| 8 | + [:room_id, { | |
| 9 | + :placeholder => '#dev', | |
| 10 | + :label => 'Room where Hubot should notify' | |
| 11 | + }] | |
| 12 | + ] | |
| 13 | + | |
| 14 | + def check_params | |
| 15 | + if Fields.detect {|f| self[f[0]].blank? } | |
| 16 | + errors.add :base, 'You must specify the URL of your hubot' | |
| 17 | + end | |
| 18 | + end | |
| 19 | + | |
| 20 | + def url | |
| 21 | + api_token | |
| 22 | + end | |
| 23 | + | |
| 24 | + def message_for_hubot(problem) | |
| 25 | + notification_description(problem) | |
| 26 | + end | |
| 27 | + | |
| 28 | + def create_notification(problem) | |
| 29 | + HTTParty.post(url, :body => {:message => message_for_hubot(problem), :room => room_id}) | |
| 30 | + end | |
| 31 | +end | |
| 32 | + | ... | ... |
spec/fabricators/notification_service_fabricator.rb
| ... | ... | @@ -5,6 +5,6 @@ Fabricator :notification_service do |
| 5 | 5 | subdomain { sequence :word } |
| 6 | 6 | end |
| 7 | 7 | |
| 8 | -%w(campfire gtalk hipchat hoiio pushover).each do |t| | |
| 8 | +%w(campfire gtalk hipchat hoiio pushover hubot).each do |t| | |
| 9 | 9 | Fabricator "#{t}_notification_service".to_sym, :from => :notification_service, :class_name => "NotificationService::#{t.camelcase}Service" |
| 10 | 10 | end | ... | ... |
| ... | ... | @@ -0,0 +1,15 @@ |
| 1 | +require 'spec_helper' | |
| 2 | + | |
| 3 | +describe NotificationService::HubotService do | |
| 4 | + it "it should send a notification to Hubot" do | |
| 5 | + # setup | |
| 6 | + notice = Fabricate :notice | |
| 7 | + notification_service = Fabricate :hubot_notification_service, :app => notice.app | |
| 8 | + problem = notice.problem | |
| 9 | + | |
| 10 | + # faraday stubbing | |
| 11 | + HTTParty.should_receive(:post).with(notification_service.api_token, :body => {:message => '[production][foo#bar] FooError: Too Much Bar', :room => notification_service.room_id}).and_return(true) | |
| 12 | + | |
| 13 | + notification_service.create_notification(problem) | |
| 14 | + end | |
| 15 | +end | ... | ... |