diff --git a/Gemfile b/Gemfile
index dc8ce30..dc785eb 100644
--- a/Gemfile
+++ b/Gemfile
@@ -65,6 +65,8 @@ gem 'hoi'
gem 'rushover'
# Hubot
gem 'httparty'
+# Flowdock
+gem 'flowdock'
# Authentication
# ---------------------------------------
diff --git a/Gemfile.lock b/Gemfile.lock
index 690c402..96727f2 100644
--- a/Gemfile.lock
+++ b/Gemfile.lock
@@ -122,6 +122,9 @@ GEM
faraday_middleware (0.8.8)
faraday (>= 0.7.4, < 0.9)
ffi (1.8.1)
+ flowdock (0.3.1)
+ httparty (~> 0.7)
+ multi_json
foreman (0.63.0)
dotenv (>= 0.7)
thor (>= 0.13.6)
@@ -397,6 +400,7 @@ DEPENDENCIES
email_spec
execjs
fabrication (~> 1.3.0)
+ flowdock
foreman
gitlab!
haml
diff --git a/app/assets/images/flowdock_create.png b/app/assets/images/flowdock_create.png
new file mode 100644
index 0000000..a18c89c
Binary files /dev/null and b/app/assets/images/flowdock_create.png differ
diff --git a/app/assets/images/flowdock_goto.png b/app/assets/images/flowdock_goto.png
new file mode 100644
index 0000000..a18c89c
Binary files /dev/null and b/app/assets/images/flowdock_goto.png differ
diff --git a/app/assets/images/flowdock_inactive.png b/app/assets/images/flowdock_inactive.png
new file mode 100644
index 0000000..e670234
Binary files /dev/null and b/app/assets/images/flowdock_inactive.png differ
diff --git a/app/models/notification_services/flowdock_service.rb b/app/models/notification_services/flowdock_service.rb
new file mode 100644
index 0000000..04ab4eb
--- /dev/null
+++ b/app/models/notification_services/flowdock_service.rb
@@ -0,0 +1,45 @@
+if defined? Flowdock
+ class NotificationServices::FlowdockService < NotificationService
+ Label = 'flowdock'
+ Fields += [
+ [
+ :api_token, {
+ :label => 'Flow API Token',
+ :placeholder => '123456789abcdef123456789abcdefgh'
+ }
+ ]
+ ]
+
+ def check_params
+ if Fields.any? { |f, _| self[f].blank? }
+ errors.add :base, 'You must specify your Flowdock(Flow) API token'
+ end
+ end
+
+ def url
+ 'https://www.flowdock.com/session'
+ end
+
+ def create_notification(problem)
+ flow = Flowdock::Flow.new(:api_token => api_token, :source => "Errbit", :from => {:name => "Errbit", :address => Errbit::Config.email_from})
+ subject = "[#{problem.environment}] #{problem.message.to_s.truncate(100)}"
+ url = app_problem_url problem.app, problem
+ flow.push_to_team_inbox(:subject => subject, :content => content(problem, url), :project => project_name(problem), :link => url)
+ end
+
+ private
+
+ # can only contain alphanumeric characters and underscores
+ def project_name(problem)
+ problem.app.name.gsub /[^0-9a-z_]/i, ''
+ end
+
+ def content(problem, url)
+ full_description = "[#{ problem.environment }][#{ problem.where }] #{problem.message.to_s}"
+ <<-MSG.strip_heredoc
+ #{ERB::Util.html_escape full_description}
+ #{url}
+ MSG
+ end
+ end
+end
diff --git a/spec/fabricators/notification_service_fabricator.rb b/spec/fabricators/notification_service_fabricator.rb
index 2f1e122..5814d48 100644
--- a/spec/fabricators/notification_service_fabricator.rb
+++ b/spec/fabricators/notification_service_fabricator.rb
@@ -12,6 +12,6 @@ Fabricator :gtalk_notification_service, :from => :notification_service, :class_n
service { sequence :word }
end
-%w(campfire hipchat hoiio pushover hubot webhook).each do |t|
+%w(campfire flowdock hipchat hoiio hubot pushover webhook).each do |t|
Fabricator "#{t}_notification_service".to_sym, :from => :notification_service, :class_name => "NotificationService::#{t.camelcase}Service"
end
diff --git a/spec/models/notification_service/flowdock_service_spec.rb b/spec/models/notification_service/flowdock_service_spec.rb
new file mode 100644
index 0000000..66be9b8
--- /dev/null
+++ b/spec/models/notification_service/flowdock_service_spec.rb
@@ -0,0 +1,17 @@
+require 'spec_helper'
+
+describe NotificationServices::FlowdockService do
+ let(:service) { Fabricate.build(:flowdock_notification_service) }
+ let(:app) { Fabricate(:app, :name => 'App #3') }
+ let(:problem) { Fabricate(:problem, :app => app, :message => '<3') }
+
+ it 'sends message in appropriate format' do
+ Flowdock::Flow.any_instance.should_receive(:push_to_team_inbox) do |*args|
+ args.first[:content].should_not include('<3')
+ args.first[:content].should include('<3')
+
+ args.first[:project].should eq('App3')
+ end
+ service.create_notification(problem)
+ end
+end
--
libgit2 0.21.2