Commit 0b34e1a5ed2e9fa9b69964d1d0ec481b40fb80c8
Exists in
master
and in
1 other branch
Merge pull request #504 from nfedyashev/flowdock_notification_adapter
Conflicts: Gemfile.lock
Showing
8 changed files
with
69 additions
and
2 deletions
Show diff stats
Gemfile
Gemfile.lock
... | ... | @@ -123,7 +123,9 @@ GEM |
123 | 123 | multipart-post (~> 1.1) |
124 | 124 | faraday_middleware (0.8.8) |
125 | 125 | faraday (>= 0.7.4, < 0.9) |
126 | - ffi (1.9.0) | |
126 | + flowdock (0.3.1) | |
127 | + httparty (~> 0.7) | |
128 | + multi_json | |
127 | 129 | foreman (0.63.0) |
128 | 130 | dotenv (>= 0.7) |
129 | 131 | thor (>= 0.13.6) |
... | ... | @@ -401,6 +403,7 @@ DEPENDENCIES |
401 | 403 | email_spec |
402 | 404 | execjs |
403 | 405 | fabrication (~> 1.3.0) |
406 | + flowdock | |
404 | 407 | foreman |
405 | 408 | gitlab! |
406 | 409 | haml | ... | ... |
1.18 KB
1.18 KB
1.1 KB
... | ... | @@ -0,0 +1,45 @@ |
1 | +if defined? Flowdock | |
2 | + class NotificationServices::FlowdockService < NotificationService | |
3 | + Label = 'flowdock' | |
4 | + Fields += [ | |
5 | + [ | |
6 | + :api_token, { | |
7 | + :label => 'Flow API Token', | |
8 | + :placeholder => '123456789abcdef123456789abcdefgh' | |
9 | + } | |
10 | + ] | |
11 | + ] | |
12 | + | |
13 | + def check_params | |
14 | + if Fields.any? { |f, _| self[f].blank? } | |
15 | + errors.add :base, 'You must specify your Flowdock(Flow) API token' | |
16 | + end | |
17 | + end | |
18 | + | |
19 | + def url | |
20 | + 'https://www.flowdock.com/session' | |
21 | + end | |
22 | + | |
23 | + def create_notification(problem) | |
24 | + flow = Flowdock::Flow.new(:api_token => api_token, :source => "Errbit", :from => {:name => "Errbit", :address => 'support@flowdock.com'}) | |
25 | + subject = "[#{problem.environment}] #{problem.message.to_s.truncate(100)}" | |
26 | + url = app_problem_url problem.app, problem | |
27 | + flow.push_to_team_inbox(:subject => subject, :content => content(problem, url), :project => project_name(problem), :link => url) | |
28 | + end | |
29 | + | |
30 | + private | |
31 | + | |
32 | + # can only contain alphanumeric characters and underscores | |
33 | + def project_name(problem) | |
34 | + problem.app.name.gsub /[^0-9a-z_]/i, '' | |
35 | + end | |
36 | + | |
37 | + def content(problem, url) | |
38 | + full_description = "[#{ problem.environment }][#{ problem.where }] #{problem.message.to_s}" | |
39 | + <<-MSG.strip_heredoc | |
40 | + #{ERB::Util.html_escape full_description}<br> | |
41 | + <a href="#{url}">#{url}</a> | |
42 | + MSG | |
43 | + end | |
44 | + end | |
45 | +end | ... | ... |
spec/fabricators/notification_service_fabricator.rb
... | ... | @@ -12,6 +12,6 @@ Fabricator :gtalk_notification_service, :from => :notification_service, :class_n |
12 | 12 | service { sequence :word } |
13 | 13 | end |
14 | 14 | |
15 | -%w(campfire hipchat hoiio pushover hubot webhook).each do |t| | |
15 | +%w(campfire flowdock hipchat hoiio hubot pushover webhook).each do |t| | |
16 | 16 | Fabricator "#{t}_notification_service".to_sym, :from => :notification_service, :class_name => "NotificationService::#{t.camelcase}Service" |
17 | 17 | end | ... | ... |
spec/models/notification_service/flowdock_service_spec.rb
0 → 100644
... | ... | @@ -0,0 +1,17 @@ |
1 | +require 'spec_helper' | |
2 | + | |
3 | +describe NotificationServices::FlowdockService do | |
4 | + let(:service) { Fabricate.build(:flowdock_notification_service) } | |
5 | + let(:app) { Fabricate(:app, :name => 'App #3') } | |
6 | + let(:problem) { Fabricate(:problem, :app => app, :message => '<3') } | |
7 | + | |
8 | + it 'sends message in appropriate format' do | |
9 | + Flowdock::Flow.any_instance.should_receive(:push_to_team_inbox) do |*args| | |
10 | + args.first[:content].should_not include('<3') | |
11 | + args.first[:content].should include('<3') | |
12 | + | |
13 | + args.first[:project].should eq('App3') | |
14 | + end | |
15 | + service.create_notification(problem) | |
16 | + end | |
17 | +end | ... | ... |