Commit e0fe8d1cd8bc26f33fd20a51cb70d8ce106fc491

Authored by Vasiliy Ermolovich
2 parents 530187bf 2b0d5900
Exists in master and in 1 other branch production

Merge pull request #373 from luxflux/hubot-notification

Hubot notification service
Gemfile
... ... @@ -54,6 +54,8 @@ gem 'xmpp4r'
54 54 gem 'hoi'
55 55 # Pushover (iOS Push notifications)
56 56 gem 'rushover'
  57 +# Hubot
  58 +gem 'httparty'
57 59  
58 60 # Authentication
59 61 # ---------------------------------------
... ...
Gemfile.lock
... ... @@ -351,6 +351,7 @@ DEPENDENCIES
351 351 hoi
352 352 hoptoad_notifier (~> 2.4)
353 353 htmlentities (~> 4.3.0)
  354 + httparty
354 355 inherited_resources
355 356 kaminari (>= 0.14.1)
356 357 launchy
... ...
app/assets/images/hubot_create.png 0 → 100644

4.96 KB

app/assets/images/hubot_goto.png 0 → 100644

4.96 KB

app/assets/images/hubot_inactive.png 0 → 100644

4.78 KB

app/models/notification_services/hubot_service.rb 0 → 100644
... ... @@ -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
... ...
spec/models/notification_service/hubot_service_spec.rb 0 → 100644
... ... @@ -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
... ...